Results 1 to 7 of 7

Thread: Perl: Keeping Leading Zeros

  1. #1
    Join Date
    Oct 2006
    Location
    St. Louis
    Beans
    52
    Distro
    Ubuntu 11.04 Natty Narwhal

    Perl: Keeping Leading Zeros [RESOLVED]

    There might be better places to ask but I already have an account here and like this ravenous crowd.

    So, I have a script that uses an incrementing variable within a filename. That filename is generated using a leading zero for the digits "01" through "09." When I increment in the script, it drops the leading zero off rendering the script unable to locate the file.

    Code:
    for ($day = 01; $day < 31; $day++) {
            system ("ssh remote_machine \"cat /log/reports/$year/$month/$day/summary_$year-$month-$day.txt | grep -v 'whatever'\" >> $temp_file 2>/dev/null");
    Thanks!?
    Last edited by Hase; September 13th, 2007 at 08:49 PM. Reason: Resolved

  2. #2
    Join Date
    Jun 2006
    Location
    CT, USA
    Beans
    5,267
    Distro
    Ubuntu 6.10 Edgy

    Re: Perl: Keeping Leading Zeros [RESOLVED]


  3. #3
    Join Date
    Oct 2006
    Location
    St. Louis
    Beans
    52
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Perl: Keeping Leading Zeros

    Code:
    for ($day = "01"; "$day" < 31; $day++) {
            system ("ssh remote_machine \"cat /log/reports/$year/$month/$day/summary_$year-$month-$day.txt | grep -v 'whatever'\" >> $temp_file 2>/dev/null");

  4. #4
    Join Date
    Oct 2006
    Location
    St. Louis
    Beans
    52
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Perl: Keeping Leading Zeros [RESOLVED]

    Thanks, I was googling the wrong thing for two hours.

    I think that the solution I stumbled across is much more straight forward though, since I'm not trying to "re"-format, just keep formatting.

  5. #5
    Join Date
    Jun 2006
    Location
    CT, USA
    Beans
    5,267
    Distro
    Ubuntu 6.10 Edgy

    Re: Perl: Keeping Leading Zeros [RESOLVED]

    I know how it hurts: You know **exactly** that answer is trivial, but for hour cannot whip up decent keywords for Google... Doing it all the time, always learn something new unexpectedly...

  6. #6
    Join Date
    Mar 2007
    Location
    Your Closet
    Beans
    380
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Perl: Keeping Leading Zeros

    Those lines are very long, you could maybe split them up a bit like this.
    Code:
    for ($day = 1; $day < 31; $day++)
    {
    	$file = sprintf "/log/reports/$year/$month/%02d/summary_$year-$month-$day.txt", $day;
    	system ("ssh remote_machine \"cat '$file' | grep -v 'whatever'\" >> $temp_file 2>/dev/null");
    }
    ...

  7. #7
    Join Date
    Oct 2006
    Location
    St. Louis
    Beans
    52
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Perl: Keeping Leading Zeros

    I'll play around with that on Monday. Thanks all!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •