Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How to replace spaces with different chars?

by kcott (Archbishop)
on Jul 07, 2022 at 14:05 UTC ( #11145331=note: print w/replies, xml ) Need Help??


in reply to How to replace spaces with different chars?

In my initial response I answered your question about using system; however, it occurs to me that you probably want to capture that output and do something with it. So, if you replace

system("ls -1 $datum");

with

my @matches = `ls -1 $datum`;

you'll now have an array of matches that you can process further. If that processing was

print for @matches;

you'll get identical output to what I originally posted.

— Ken

Replies are listed 'Best First'.
Re^2: How to replace spaces with different chars?
by LanX (Sage) on Jul 07, 2022 at 14:15 UTC
    why not use

    my @matches = glob($datum)

    or

    my @matches = <$datum>

    directly?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      This was a follow-up to my previous post about system, which has:

      "This is not what you want to use to capture the output from a command; for that you should use merely backticks or qx//, ..."

      Of course, TMTOWTDI. :-)

      — Ken

        Hi Ken

        Sorry, I have to disagree.

        For numerous reasons it's best practice not to shell out for something which can be done inside Perl. (portability, performance, maintenance, security, ...)

        It's even a bit worse, because ls is useless, if you just need the shell's globbing.

        TMTOWTDI only covers this, if there is a good reason.

        Anyway, let me point you to older discussions instead of reiterating the reasons

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

        ) thanks to eyepops++ for keeping this listed in his homenode! :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2022-09-30 07:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (125 votes). Check out past polls.

    Notices?