Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help explain coding - thanks!

Status
Not open for further replies.

biry

Technical User
Nov 5, 2004
127
CA
hi, being new to perl i was wondering what the explaination of these lines are... what are they doing:

Code:
$temp=$ENV{'QUERY_STRING'}; 

$temp =~ s/%40/@/g; 

@pairs=split(/&/,$temp); 
foreach $item(@pairs) { 
 ($key,$content)=split (/=/,$item,2); 
 $content=~tr/+/ /; 
 $content=~ s/%(..)/pack("c",hex($1))/ge; 
 $fields{$key}=$content; 
}

$file=$fields{'website'};
#$file=~s/\..+//gi;

use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
$ua = new LWP::UserAgent;

$dir= $fields{'ws'};

#my $location="file://c:/$dir/$file";
my $absolute="[URL unfurl="true"]http://www.company.com/edgar2";[/URL]

my $companyName=$fields{'companyName'};
my $website=$fields{'website'};
my $location="[URL unfurl="true"]http://www.company.com/edgar2/edgar-download/"[/URL] . $website;

my $fileType;

my $search=$fields{'companyName'};
 
I imagine you're asking about the first half, since the second half is just declaring modules not used and setting a bunch of scalars without doing anything with them. And about that first half...it's some hand-rolled form data (well, query string) parsing that's greatly frowned upon. You should really use CGI or one of its bretheren instead of that.

Outside of that, can you make a more specific question so we can better help?

________________________________________
Andrew

I work for a gift card company!
 
why is it frowned upon?

also what does the temp variable get set to i nthis line, can you please explain this line:
$temp =~ s/%40/@/g;

also when you mention "should really use CGI".. what search term would i look for on this at this forum and google?

thanks
 
$temp =~ s/%40/@/g;

This is a regular expression to replace %40 with @ in variable tmep. It looks like someone has saved maybe an email address in $ENV{'QUERY_STRING'} from the browser. The browser replace @ with %40 when you post/get data in a form. So you need to convert it back in the script when you receive them.

When icrf said "should really use CGI" He meant use the PERL modeule CGI. It is a module that allow you to extract <input> data from an html form. The word "use" is a keyword in PERL which means load up this module called "CGI". Take a look at This should give you an idea what this module is
 
This is a good resource for reasons-why-not-using-CGI.pm-is-a-very-very-bad-thing-altogether.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top