Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Re: Need a better way to count input lines

by Theo (Priest)
on May 07, 2004 at 17:38 UTC ( #351548=note: print w/replies, xml ) Need Help??

in reply to Re: Need a better way to count input lines
in thread Need a better way to count input lines

Ahh! The lights come on! (Then they go dim again) I changed the
$fname =~ s/^\s+(.+?)\W*$/$1/;
$fname =~ s/^\s*(.+?)\W*$/$1/;
and the problem went away. (Of course it did. I should have seen that.) I can see why with the '+' it didn't work right, but why would the failure manifest as a CR at the end of $fname?
But I am perplexed about the split itself. I replaced the (",") with (",\s*") and got the error:
Unrecognized escape \s passed through at line 28.
The paren/quote format worked fine with just a comma but broke with the addition of the space char class. Did I just get lucky the first way?

As to the LIMIT option, my Llama book doesn't explain it. Does the 2 relate the expectation of having two char within the match?

(so many nodes and so little time ... )

Replies are listed 'Best First'.
Re: Re: Re: Need a better way to count input lines
by hv (Parson) on May 07, 2004 at 20:09 UTC

    ... but why would the failure manifest as a CR at the end of $fname?

    I suspect the text, created under Windows, has CRLF as the line terminator; running the script under Solaris the chomp is removing the LF but not the CR, so the CR was getting removed instead by the $fname substitution - but only when the substitution actually happened.

    As for split, please take a look through perldoc -f split. First, note that the first parameter is shown as /PATTERN/; if you supply this parameter as a pattern (eg /,\s*/) it gets parsed as a pattern and does the right thing. If you supply a quoted string instead (eg ",\s*") perl will treat that first as a quoted string - in which case "\s" gives the warning, and gets converted to "s" - and the resulting string is then converted to a regexp further down the line.

    You'll also find there far more than you ever wanted to know about the LIMIT argument.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://351548]
[GotToBTru]: I remember hearing about somebody misplacing a list of code phrases or something
[marto]: 12345
[GotToBTru]: the "nuclear codes" are in the case cuffed to the wrist of some guy
[LanX]: not always
[LanX]: it's up to the Supreme commander
[GotToBTru]: we don't have one of those ;)
[LanX]: commander in chief whatever

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2017-01-20 12:43 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (174 votes). Check out past polls.