Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: What is the difference?

by zby (Vicar)
on Apr 08, 2003 at 14:29 UTC ( [id://248938]=note: print w/replies, xml ) Need Help??


in reply to What is the difference?

Look at the output without wc. The += operator does not concatenate the right side to the left. It is the .= operator that does it.

Update Ok - there is no wc in the second example. But once again look at the line with += the left side of it is a list - a list does not return its length in a scalar context (only an array do it).

Update As Abigail-II pointed out split in scalar context returns the number of fields.

Replies are listed 'Best First'.
Re: What is the difference?
by Abigail-II (Bishop) on Apr 08, 2003 at 14:38 UTC
    Well, yeah, += doesn't do that. += doesn't multiple the right hand side with the left hand side either.

    You're the second person to assume something needs to be concatenated. Why, I have no idea. split doesn't return a string, it returns a number, and the program is counting things. I see no reason at all to come up with concatenation.

    To answer the question, split returns the number of fields. And if you split on [ \t]*, the number of fields isn't necessaryly the same as the number of characters.

    Abigail

Re: Re: What is the difference?
by jasonk (Parson) on Apr 08, 2003 at 14:33 UTC

    Look at the command line, the second one doesn't use wc at all, it does the counting itself.


    We're not surrounded, we're in a target-rich environment!

Log In?
Username:
Password:

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

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

    No recent polls found