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

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


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

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"; }


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2016-10-25 00:26 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (313 votes). Check out past polls.