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: Beginner:
Substitution of Blank with Underscore

 



sumit2606
New User

Feb 14, 2015, 5:41 AM

Post #1 of 4 (2037 views)
Substitution of Blank with Underscore Can't Post

For the Below Code the output value of fdir is Blank. Can any one Help how can I replace space with _? Also how can I pass the Value of $fdir, $FILTER to a Subroutine?

open ffilter,"Filter.txt" ;
while (<ffilter>) {
my $FILTER = $_;
chomp ($FILTER);
my $fdir = $FILTER;
my $fdir =~ s/ /_/g;
print ("\t FILTER: $fdir");
}
close;

Filter.txt file content is

ASD BGH

ASD_BJY

MAP


FishMonger
Veteran / Moderator

Feb 14, 2015, 6:09 AM

Post #2 of 4 (2036 views)
Re: [sumit2606] Substitution of Blank with Underscore [In reply to] Can't Post

There are at least 5 problems with that code, but I'll start with what appears to be missing from your script.

Add these 2 pragmas to the beginning of the script.

Code
use strict; 
use warnings;


With those in place, you will receive a key error message regarding the problem you're having.

To learn about passing vars to a subroutine, you should read the related perl documentation via this command:

Quote
c:\test>perldoc perlsub



sumit2606
New User

Feb 14, 2015, 8:06 AM

Post #3 of 4 (2033 views)
Re: [FishMonger] Substitution of Blank with Underscore [In reply to] Can't Post

Thanks

I was able to rectify the substitution problem. Is it possible to use $FILTER variable in any Subroutine


FishMonger
Veteran / Moderator

Feb 14, 2015, 8:14 AM

Post #4 of 4 (2031 views)
Re: [sumit2606] Substitution of Blank with Underscore [In reply to] Can't Post


In Reply To
Thanks

Is it possible to use $FILTER variable in any Subroutine


Yes, as long as the subroutine call is in inside that while loop.


(This post was edited by FishMonger on Feb 14, 2015, 8:14 AM)

 
 


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

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