Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: giving same name to two files

by Anonymous Monk
on Jul 17, 2013 at 10:07 UTC ( #1044779=note: print w/ replies, xml ) Need Help??


in reply to Re: giving same name to two files
in thread giving same name to two files

hey

your code is working when the user inputs the name correctly the first time , but if he gives a wrong name the first time , so i am doing this

while (!-e $filename) { print "-*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*--*- +*--*-*--*-*--*-*--*-*--*-*--*-*--*-*-\n"; print STDERR "\n$filename not found. \n Ensure that you have + given the correct file name\n and the file exists in the working dir +ectory \n."; print "Re-enter filename, or q to quit: "; $filename = <STDIN>; chomp $filename; # my @filenam = split ('\.', $filename); exit() if $filename eq "q"; }

the line commented out by me is what I did so everytime user inputs the file name it should get updated but its not happening , can you tell me why


Comment on Re^2: giving same name to two files
Download Code
Replies are listed 'Best First'.
Re^3: giving same name to two files
by mtmcc (Hermit) on Jul 17, 2013 at 12:18 UTC
    Is this what you mean?

    #!/usr/bin/perl use strict; use warnings; my $ending = "txt"; print STDERR "Enter filename: "; my $fileName = <STDIN>; chomp $fileName; while (!-e "$fileName") { print STDERR "$fileName not found. Try again, or quit (q): "; $fileName = <STDIN>; chomp $fileName; exit () if $fileName eq "q"; } my @name = split ('\.', $fileName); $name[$#name] = $ending if @name >= 2; push(@name, $ending) if @name == 1; my $newFileName = join(".", @name); print STDERR "\nOLD: $fileName\nNEW: $newFileName\n\n"; open (IN, "<", $fileName); open (OUT, ">", $newFileName); while (<IN>) { #do stuff... #print OUT "output"; }

    -Michael

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2015-07-08 02:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls