Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^2: get current script as text

by pvaldes (Chaplain)
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 prints


What I'm doing wrong?

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://966863]
[choroba]: preparing the trip to Vietnam + buying a new car = enough fun
[Corion]: choroba: Yeah, that's a lot of "fun" for one week...
[Corion]: I guess I should stage some product photos for Sane Dots Supplies ;)
[marto]: I had some ideas about that Corion
[marto]: I'll send a message over the weekend maybe :P
[Corion]: choroba: I avoided the "fun" of emergency shopping for a new flat iron by trying the flat iron without the timer that sat between it and the mains power. Seems as if just the timer is broken.
[Corion]: marto: Heh, would be cool!
Corion munches on the traditional German winter fruit, strawberries. Imported from Spain at the price of EUR 0.77 per 150g - not really cheap but surprisingly good for a winter produce

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2017-01-20 10:19 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (174 votes). Check out past polls.