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

Re: One to one file output idiom

by 1nickt (Canon)
on Jan 15, 2020 at 18:15 UTC ( [id://11111452]=note: print w/replies, xml ) Need Help??


in reply to One to one file output idiom

Hello Eily, I use Path::Tiny for almost all the file things.

$ rm foo* bar* $ echo foo > foo $ echo bar > bar
$ perl -MPath::Tiny -wnE 'sub baz {uc} chomp; my $in = path($_); $in-> +sibling("$_.new")->spew(baz($in->slurp));' foo bar
$ cat foo.new FOO $ cat bar.new BAR

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: One to one file output idiom
by Eily (Monsignor) on Jan 16, 2020 at 09:20 UTC

    Is it just me or are the method names of this module really not helfpul? I had to loop spew in the dictionary because I wasn't sure of the implication, I knew of "spewing nonsense" but I didn't realize the word had such a negative connotation to it. And somehow I would understand spew to be the reverse action (getting data out of a file, not in). And I got what sibling does because I knew what to expect. Beyond that I guess it is a pretty short and "clean" (except for the confusing names) way to do what I want.

    Also, here your code works because each file contains its own name, but I think it should be path(shift), without the -n option

      Well, since "slurp" is reading a file in, it makes sense to use the opposite of "slurp" for writing. So, for me, "spew" looks completely intuitive ,-)

      you seem to see it from the view of the file. Hmmm, yes, from an OO view the opposite might make sense…

        Oh I guess you're right. Although slurp isn't so much more explicit IMHO, I'm just used to it because it's commonly used with perl, but I don't think I've ever seen it used for any other language.

        I'm not a native speaker, but for me to "spit" seems as a more natural opposite to "slurp".

        To "spew" in contrast also means to vomit.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

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

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

    No recent polls found