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:
how to understand this code segment

 



huaiyanggongzi
Novice

Dec 17, 2011, 8:19 PM

Post #1 of 2 (425 views)
how to understand this code segment Can't Post

When reading a file processing program, I read the following code:

my $fileName = substr($_, index($_, \#))

$fileName =~ s/\s+//g;

$fileName =~ s/^\#//;

$fileName =~ s/^,*\///;

$fileName =~ s/\.txt.*$//;

s/\s+\#.*$//;

I am really confusing about what do these code function? I know they have used regular expression, but how to analyze them?


BillKSmith
Veteran

Dec 18, 2011, 4:51 AM

Post #2 of 2 (408 views)
Re: [huaiyanggongzi] how to understand this code segment [In reply to] Can't Post


Code
my $fileName = substr($_, index($_, \#))  # Extract filename from $_ 

$fileName =~ s/\s+//g; # Remove all whitespace from filename

$fileName =~ s/^\#//; # Remove leading sharp sign from filename


$fileName =~ s/^,*\///; # Remove leading comma from filename

$fileName =~ s/\.txt.*$//; # Remove '.txt' and everything else to the end of the string from filename

s/\s+\#.*$//; # Remove sharp and everything after it from $_

Good Luck,
Bill

 
 


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

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