- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: 1 more Perl ?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2004 12:14 AM
07-27-2004 12:14 AM
thus:
while (read(I_FILE, $buf, 100)) {
($mychar) = substr($buf, 0, 1);
}
to determine if $mychar is the 'null' (\0) char?
I need to make a choice based on it being null or not, and I can't seem to get the compare nailed down.
Thanks,
Rt.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2004 12:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2004 12:27 AM
07-27-2004 12:27 AM
Re: 1 more Perl ?
$mychar =~ m/^\0/
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2004 01:31 AM
07-27-2004 01:31 AM
Re: 1 more Perl ?
Thanks again.
Rt.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2004 08:19 PM
07-27-2004 08:19 PM
Re: 1 more Perl ?
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2004 11:56 PM
07-27-2004 11:56 PM
Re: 1 more Perl ?
Rt.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2004 12:02 AM
07-28-2004 12:02 AM
Re: 1 more Perl ?
About matching expressions : =~ is an operator to parse the left operator through a regular expression onthe right. Most used are m// (wich search expression for the matching pattern) and s///g (which replaces first pattern by second).
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2004 01:01 AM
07-28-2004 01:01 AM
Re: 1 more Perl ?
An absolute must for anyone using vi, perl, awk, grep, sh, sed, emacs, ...
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2004 01:21 AM
07-28-2004 01:21 AM
Re: 1 more Perl ?
while procura's solution may be the more Perlish one, I wouldn't demean yours in saying his is "better".
I do have the feeling that a Regex match is more expensive than your function invocation.
But procura probably will prove me wrong with a profiler or Benchmark.pm result. ;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2004 01:46 AM
07-28-2004 01:46 AM
Re: 1 more Perl ?
--8<---
use strict;
use warnings;
use Benchmark;
my @txt = map {
chr (int rand 256) . "x" x 20;
} 0 .. 500;
timethese (-5, {
sub_str0 => 'for (@txt) { ord (substr ($_, 0, 1)) == 0 }',
sub_str1 => 'for (@txt) { (ord $_) == 0 }',
reg_expr => 'for (@txt) { m/^\0/ }',
});
-->8---
lt09:/tmp 115 > perl xx.pl
Benchmark: running reg_expr, sub_str0, sub_str1 for at least 5 CPU seconds...
reg_expr: 5 wallclock secs ( 5.20 usr + 0.00 sys = 5.20 CPU) @ 1837946.73/s (n=9557323)
sub_str0: 4 wallclock secs ( 5.17 usr + 0.01 sys = 5.18 CPU) @ 1859805.41/s (n=9633792)
sub_str1: 5 wallclock secs ( 5.23 usr + 0.01 sys = 5.24 CPU) @ 1838507.82/s (n=9633781)
lt09:/tmp 116 > perl xx.pl
Benchmark: running reg_expr, sub_str0, sub_str1 for at least 5 CPU seconds...
reg_expr: 7 wallclock secs ( 5.21 usr + 0.01 sys = 5.22 CPU) @ 1830904.79/s (n=9557323)
sub_str0: 5 wallclock secs ( 5.31 usr + 0.00 sys = 5.31 CPU) @ 1814271.37/s (n=9633781)
sub_str1: 5 wallclock secs ( 5.14 usr + 0.00 sys = 5.14 CPU) @ 1815065.95/s (n=9329439)
lt09:/tmp 117 >
In the second run thre regular expression is fastest.
If I change timethese to cmpthese,
lt09:/tmp 121 > perl xx.pl
Rate sub_str0 reg_expr sub_str1
sub_str0 1815759/s -- -1% -3%
reg_expr 1842023/s 1% -- -2%
sub_str1 1881363/s 4% 2% --
lt09:/tmp 122 > perl xx.pl
Rate sub_str1 reg_expr sub_str0
sub_str1 1849096/s -- -0% -2%
reg_expr 1855576/s 0% -- -2%
sub_str0 1890459/s 2% 2% --
lt09:/tmp 123 > perl xx.pl
Rate sub_str0 sub_str1 reg_expr
sub_str0 1833602/s -- -1% -2%
sub_str1 1859231/s 1% -- -1%
reg_expr 1876165/s 2% 1% --
lt09:/tmp 124 >
So the choice is yours: it realy doesn't matetr for simple things like this
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2004 02:21 AM
07-28-2004 02:21 AM
Re: 1 more Perl ?
"Better" doesn't mean "less cpu costing". Some arguments may be :
First of all using "=~ m//" solution will update $_. This will probably make things easier for the continuation (and maybe make an other instruction use less CPU :)
Second is that perl stands for Practical Extracting and Reporting Language (If I remember correctly the official meaning). So parsing an expression is more "perl minded".
This are the only two that comes now, but Procura will maybe add some ;)
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2004 02:29 AM
07-28-2004 02:29 AM
Re: 1 more Perl ?
$my_sting =~ m/(?{$my_string=''})/;
or
$my_sting =~ m/(?{{$my_string=''}})/;
in which case I hope you know - and intend - what you are doing
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2004 02:55 AM
07-28-2004 02:55 AM
Re: 1 more Perl ?
Sorry for this stupid saying.
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2004 07:18 AM
07-28-2004 07:18 AM
Re: 1 more Perl ?
I did manage to find an explanation of both original syntax's, so I (hopefully) learned something!
Rt.