Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
The stupid question is the question not asked
 
PerlMonks  

Re^2: get current script as text

by pvaldes (Hermit)
on Apr 24, 2012 at 14:45 UTC ( #966863=note: print w/ replies, xml ) Need Help??


in reply to Re: get current script as text
in thread get current script as text

mmh... Your code don't show nothing in my computer (?)

This was my idea, but without success still, close, but not cigar... I wonder why

open (my $foo, $0); # binmode $foo, raw; # nothing changes with or without this line print $foo; close $foo;

perl script.pl prints

GLOB(0x9b717dc)

What I'm doing wrong?


Comment on Re^2: get current script as text
Select or Download Code
Re^3: get current script as text
by BrowserUk (Pope) on Apr 24, 2012 at 14:51 UTC
    mmh... Your code don't show nothing in my computer (?)

    My code should work fine anywhere. Post the exact code you are using that is failing.

    open (my $foo, $0); print $foo; close $foo; What I'm doing wrong?

    You are never reading from the file you opened.

    You are printing the filehandle you opened.

    Perhaps you meant:

    open (my $foo, $0); print <$foo>; close $foo;

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      mmh, I see... The problem is very silly. I forgot to add a last line to print the variable.

      my $codeAsText = do{ local( @ARGV, $/ ) = $0; <>; }; print $codeAsText;

      Perhaps you meant:

      open (my $foo, $0); print <$foo>; close $foo;

      Yes, This solves the problem also, thanks!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2014-04-24 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (565 votes), past polls