Re: [OT] perl regex problem
Hunter Marshall wrote:
> hhm@hmarshall:/tmp
> -> od -x junk
> 0000000 6968 0a0a 0a0a 0a0a 000a
> 0000011
> hhm@hmarshall:/tmp
> -> perl -n -e 'print "yup\n" if /\x0a/;' junk
> yup
> yup
> yup
> yup
> yup
> yup
> yup
> hhm@hmarshall:/tmp
> -> perl -n -e 'print "yup\n" if /\x0a\x0a/;' junk
This one-liner is the same as the following script:
#!/usr/bin/perl
while(<>)
{
if (/\x0a\x0a/)
{
print "yup\n";
}
}
Every iteration of the while loop, the next line from the file opened by
<> ('junk' in your case) is stored into the default variable $_. Since a
single line will only ever have one \x0a in it, the if statement will
never be true.
Matthew
Reply to: