Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: OS agnostic C&P CLI snippets with -E

by kcott (Bishop)
on Oct 18, 2021 at 19:47 UTC ( #11137700=note: print w/replies, xml ) Need Help??


in reply to OS agnostic C&P CLI snippets with -E

G'day Rolf,

For the most part, I provide complete scripts. Generally, you can use the [download] link, save the code, and run it as is; sometimes it may be necessary to change a local value, e.g. my $path = '...' (or similar).

For code that is mostly simplistic and provided for demonstration purposes, I will, in the main, use this type of format: $ perl -E '...'

In "Re: POD for use feature 'declared_refs' wrong", you'll see a whole series of these built up using very small changes. There was no way that I was going to create five separate (almost identical) scripts for this.

The demonstration code is really just that; however, it's perfectly acceptable and reasonable to check that the results are the same on your OS, Perl version, or whatever. I'm certainly no MS-DOS expert; but the following seemed like a very easy way to achieve this.

Get the version to which -E would refer; e.g.

C:\Users\ken\tmp>perl -v This is perl 5, version 26, subversion 3 (v5.26.3) built for MSWin32-x +64-multi-thread ...

Create a Perl script (e.g. pm_11137651_os_agnostic.pl) that starts with use <-E version>; (that's use 5.026; in this instance). Copy the ... part of perl -E '...' exactly and paste it after the first line. Save the file. Using the first piece of code from the OP, that should look like this:

C:\Users\ken\tmp>more pm_11137651_os_agnostic.pl use 5.026; use strict; use warnings; use feature "declared_refs"; no warnings "experimental::declared_refs"; say ref my \$scalar; say ref my \@array;

Then run it:

C:\Users\ken\tmp>perl pm_11137651_os_agnostic.pl SCALAR ARRAY

A verbatim copy of pm_11137651_os_agnostic.pl, on a Unix-style OS (Cygwin), acted in exactly the same way (except I needed cat instead of more).

ken@titan ~/tmp $ cat pm_11137651_os_agnostic.pl use 5.026; use strict; use warnings; use feature "declared_refs"; no warnings "experimental::declared_refs"; say ref my \$scalar; say ref my \@array;
ken@titan ~/tmp $ perl pm_11137651_os_agnostic.pl SCALAR ARRAY

As I indicated, I'm no expert on the MS-DOS front. There may be quicker or better ways to do this; although, this method literally only took a few seconds. Perhaps, if this is needed often, some sort of script might be a valid choice.

— Ken

Replies are listed 'Best First'.
Re^2: OS agnostic C&P CLI snippets with -E
by LanX (Sage) on Oct 19, 2021 at 09:14 UTC
    Hi Ken

    > but the following seemed like a very easy way to achieve this.

    Well, these are a handful more steps than just running

    perl COPIED CODE __END__

    As Corion pointed out you can even avoid the __END__ by typing C-z (C-c resp. Win).

    But when posting I prefer __END__ because C&P easily works for the reader.

    Even better this doesn't come anymore with your restriction of not using the single-quote in the code, because of your -E'...' delimiter.

    The purpose of this thread was finding a way to avoid typing use feature ':all' to replicate -E

    I think my 'alias' solution does it well for me locally to run -E code.

    And when posting code here, I can still expand for easy reproducibility on readers side.

    perl -Mfeature=:all CODE __END__

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2022-01-26 09:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (69 votes). Check out past polls.

    Notices?