Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: path is broken

by btrott (Parson)
on Dec 06, 2000 at 23:55 UTC ( [id://45299]=note: print w/replies, xml ) Need Help??


in reply to path is broken

Why are you using cat? Wouldn't
$line_count = `wc -l $filename`
work just as well?

Of course one could argue that you could just do the entire thing in Perl rather than using system calls; I might argue that, for instance. Here's a version of wc in Perl; you could extract the bits you need.

Or you could do something like this:

sub lines_in_file { my $f = shift; open FH, $f or die "Can't open $f: $!"; 1 while <FH>; $.; }
This would take care of your "space-in-filename" problem as well, since Perl won't care; it's only a problem when you pass it off to the shell like that.

You can use this like:

my $line_count = lines_in_file($filename);

Replies are listed 'Best First'.
Re: Re: path is broken
by a (Friar) on Dec 07, 2000 at 07:02 UTC
    'cause
    cat file | wc -l and: wc -l file
    produce different output:
    9
    vs.
    file: 9 (or some approximation)

    a

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://45299]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-23 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found