Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: counter of files? something else?

by soonix (Canon)
on Apr 23, 2015 at 13:19 UTC ( [id://1124393]=note: print w/replies, xml ) Need Help??


in reply to Re: counter of files? something else?
in thread counter of files? something else?

  • Does @files change during the loop? otherwise, you'll end up with $count having always the same value.
  • if you are inside a loop, the my variables are only for that one iteration. Is this what you want?
  • $count is not a very good variable name
I think you want:
  • before the foreach loop: my $file_number = 0;
  • in the loop: $file_number += 1;
Plus you seem to get the sigils wrong - see the first part of → perldata:
@whatever is an array, a single element of that array is $whatever[123]. @whatever[123] is an array slice.

Replies are listed 'Best First'.
Re^3: counter of files? something else?
by fasoli (Beadle) on Apr 23, 2015 at 13:40 UTC

    - No, @files doesn't change through the loop.

    - That's a good point. I'll try it differently.

    - Ok, thank you for the suggestion.

    I'll try the two final bullet points!

    As for arrays/elements/slices: thank you, I normally get them right, I mixed it up a bit when trying to explain myself.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-19 02:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found