CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
get File Name with an input redirection Perl

 



solu_abhi
New User

Dec 17, 2009, 3:55 AM

Post #1 of 8 (3332 views)
get File Name with an input redirection Perl Can't Post

Can you please provide me a solution: I need to get the file name that I am using as an input to a perl file. e.g.



perl myperl.pl < gettext.txt



I would require the name of text file(gettext.txt) in the Perl file(myperl.pl) and print the name. I donít want to print the contents, just filename.



I cannot omit the "<" part.. Its mandatory for my requirement.


FishMonger
Veteran / Moderator

Dec 17, 2009, 4:28 AM

Post #2 of 8 (3328 views)
Re: [solu_abhi] get File Name with an input redirection Perl [In reply to] Can't Post

Sorry, you need to do your own homework.


solu_abhi
New User

Dec 17, 2009, 5:45 AM

Post #3 of 8 (3321 views)
Re: [FishMonger] get File Name with an input redirection Perl [In reply to] Can't Post

Hi,

If I was so able to do it, I would not have joined this forum. It could be great if you can help me out. I know its not easy, and there lies the guru knowledge.


bichonfrise74
Novice

Dec 17, 2009, 11:05 AM

Post #4 of 8 (3306 views)
Re: [solu_abhi] get File Name with an input redirection Perl [In reply to] Can't Post

You said requirements... What are your requirements in your code?


--bichonfrise74

(This post was edited by bichonfrise74 on Dec 17, 2009, 11:05 AM)


shawnhcorey
Enthusiast


Dec 17, 2009, 11:29 AM

Post #5 of 8 (3298 views)
Re: [solu_abhi] get File Name with an input redirection Perl [In reply to] Can't Post


In Reply To
I cannot omit the "<" part.. Its mandatory for my requirement.


Then you can't do it. This redirects STDIN; perl does not know where the data is coming from. It could be a file or a pipe. There is no way to tell.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


solu_abhi
New User

Dec 17, 2009, 9:06 PM

Post #6 of 8 (3266 views)
Re: [shawnhcorey] get File Name with an input redirection Perl [In reply to] Can't Post

Hi shawnhcorey,

Thanks for your reply. Can you please elaborate your reply. Does that mean that when ever we use an indirect operator with a Input Parameter, we can't get the name of Input parameter..

My requirement is:

if I execute the code as : perl myperl.pl < mytext.DAT


I need the name of first parameter i.e. mytext.DAT

I dont need to print the contents of file but only the file name. I also tried with unshift function but of no use. I could print the contents but not the file name.

So please explain in detail, if possible. Thanks a lot.


(This post was edited by solu_abhi on Dec 17, 2009, 9:10 PM)


shawnhcorey
Enthusiast


Dec 18, 2009, 2:02 AM

Post #7 of 8 (3250 views)
Re: [solu_abhi] get File Name with an input redirection Perl [In reply to] Can't Post


In Reply To
My requirement is:

if I execute the code as : perl myperl.pl < mytext.DAT


I need the name of first parameter i.e. mytext.DAT


Redirects are handle by the shell, not Perl. The information of where the input comes from is not passed on. The redirect is not a parameter. It cannot be determined.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


solu_abhi
New User

Dec 18, 2009, 4:56 AM

Post #8 of 8 (3231 views)
Re: [shawnhcorey] get File Name with an input redirection Perl [In reply to] Can't Post

Thank a lot.. Smile

I changed my call to program as:

perl myperl.pl mytext.DAT

When its next to impossible, its wiser to modify the code and enjoy productivity. Tongue

Thanks again.. Smile

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives