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

Re: Keeping a Count in foreach

by I0 (Priest)
on Jun 17, 2002 at 18:27 UTC ( #175159=note: print w/ replies, xml ) Need Help??


in reply to Keeping a Count in foreach

foreach $e (@s) { print(($.||1..$.&&0)-1," $e\n"); }


Comment on Re: Keeping a Count in foreach
Download Code
Re^2: Keeping a Count in foreach
by particle (Vicar) on Jun 17, 2002 at 19:04 UTC
    if you're going to obfuscate it, why not

    map print(($.||1..$.&&0)-1," $_$/"),@s;
    and be done with it? {shudder}

    ~Particle *accelerates*

      10pts for using map in a void context!


      (loses 2000 xp)
        yeah, nasty code. i should probably give an englishEnglish version as contrast.

        use English; sub ONE() {1} sub ZERO() {0} for my $each (@strings) { print( ( ( $INPUT_LINE_NUMBER or ONE ) .. ( $INPUT_LINE_NUMBER and ZERO ) ) - ONE, ' ', $each, $INPUT_RECORD_SEPARATOR, ); }

        ~Particle *accelerates*

Re^2: Keeping a Count in foreach
by Anonymous Monk on May 10, 2012 at 03:41 UTC
    Hi can you please explain this syntax|1..$.&&0)-1 , i tried to get it but i am unable to understand it.
Re^2: Keeping a Count in foreach
by Anonymous Monk on May 10, 2012 at 03:41 UTC
    Hi can you please explain this syntax ($.||1..$.&&0)-1 , i tried to get it but i am unable to understand it.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2015-07-07 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls