Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Does Perl 5 (or 6?) need another built-in variable for the -F switch?

by davido (Cardinal)
on Nov 02, 2006 at 16:46 UTC ( #581921=note: print w/replies, xml ) Need Help??


in reply to Does Perl 5 (or 6?) need another built-in variable for the -F switch?

As long as we're talking about patches, perhaps $& is where the patch should be applied so that split-type matches fall within its realm.

The problem with that would be if someone, somewhere, in existing codebase is performing a pattern match, then splitting something, and then relying on $& still pertaining to the pre-split match. That may be a rare potential, but it does exist. So I guess a new variable ought to be used instead of adding functionality to $& (even if it seems to make sense to do so). Just to make it easier to remember, how about calling this new variable $^&, since its behavior would be quite similar to $&

I'm actually kind of surprised that Perl doesn't present a special variable (maybe a special hash) that contains all of the command line switches used to invoke perl. ...not the switches passed on to the script being executed, but the switches passed on to perl itself. If the hash were called %^C, it might contain data like this:

%^C = ( F => "\t", a => undef, n => undef, e => '# The actual one-liner script', );

Dave

Replies are listed 'Best First'.
Re^2: Does Perl 5 (or 6?) need another built-in variable for the -F switch?
by Hofmator (Curate) on Nov 03, 2006 at 09:33 UTC
    I like davido's suggestion of a %^C hash with the command line parameters that are used to invoke perl. This allows the programmer to use the value of F (or anything else defined on the commandline) for a join IF he/she knows that it is safe to do so - i.e. if it is not a pattern but a simple string, see duff's post in this thread.

    -- Hofmator

    Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      On Linux with a mounted /proc file system, you can find the command line parameters from /proc/$$/cmdline.

      But this (and the proposed %^C) would be tricky. Command line parameters maybe clustered. Searching for just '-F' won't do, the parameter may be passed as '-wF:', which sets the split pattern to :. However, a parameter '-iF:' won't.

      And then there is PERL5OPT.

        Well, at least perl should know which command line parameters where used when it was invoked :) and as the proposed hash %^C was supposed to be populated by perl itself, this should work out fine. This hash should then, IMO, include the command line parameters set via PERL5OPT.

        Mind you, I have no idea how difficult it would be to patch that into perl, I just said I liked the idea.

        -- Hofmator

        Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2018-11-13 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (146 votes). Check out past polls.

    Notices?