Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: changing date format in and out

by gio001 (Acolyte)
on Feb 14, 2009 at 00:23 UTC ( [id://743741]=note: print w/replies, xml ) Need Help??


in reply to Re: changing date format in and out
in thread changing date format in and out

Thanks,
well I understand and I agree that I will have to execute in a loop, what I am trying to learn is a way to create the while loop inside the perl world and not issue thousands of invocations to perl from a straight unix ksh loop, if you understand what I mean.
So can you please illustrate for me how can I structure an invocation statement(s) to perl with an incoming file name, an output file name and the real while loop as the core of what I will ask perl to execute for me?
Thanks !

Replies are listed 'Best First'.
Re^3: changing date format in and out
by McDarren (Abbot) on Feb 14, 2009 at 02:12 UTC
    The example that was given to you is the guts of what you are asking for.

    Take the code that was given to you by mr_mischief, and save it in a file (lets call it foo.pl). Then just pass your input file through that, ie:

    perl foo.pl < infile > outfile
    Although, you will probably want to change the line:
    print (gmtime $_);
    to read:
    print scalar gmtime($_);
    Or alternatively, if you want your output in local time, then:
    print scalar localtime($_);
    Hope this helps,
    Darren
      Great, thanks a lot!
      I hope not to impose on you for a very last favor, how would it be possible to consolidate this logic into a single perl line command (a one liner)?
      I hope you can show me, thanks again!
        perl -ne 'print scalar localtime' < infile > outfile
        Notes:
        - the "-n" switch, causes perl to assume a "while <>" loop (see perldoc perlrun)
        - the $_ can be dropped, because it is implicit
        - there is no need to chomp, as you probably want the newline anyway

        Cheers,
        Darren :)

Re^3: changing date format in and out
by Anonymous Monk on Feb 14, 2009 at 01:08 UTC
    Abandon KSH

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-26 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found