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!

URL's with parameters. Can't display 1

Status
Not open for further replies.

Alphabin

Programmer
Dec 8, 2002
119
CA
Hi,

I'm trying to link URL's with parameters (Links stored in flat file) and I'm not getting successful results:

Flat file is structured as follow:
Name=Home Page
Link=http://www.linkhere.com/library/display.asp?app=post&order=num

The line to display URL
print "<a href=\"$Link\">$Name</a<" . " \n ";

When the Link does not include parameters it is displayed correctly.

Thank you in advance
 
Have you tried adding a slash to the '?', making it:

A method I always use when printing html is the following:
Code:
$link="[URL unfurl="true"]http://www.linkhere.com/library/display.asp?app=post&order=num";[/URL]
$name="Home Page";

print <<EOHTML;
  <a href="$Link">$Name</a>
EOHTML
This is a lot neater and saves you the mission of have to add slashes. If you use my method you do not need to add the slash before the '?'.

Just remember that the bottom 'EOHTML' must be on a new line with no spaces before or after it, otherwise it will not work.

I hope this helps.

Sean.
 
There's no reason why you'd have to escape the ?. It's just a normal character in the string.

I suspect the problem is with the method you're using to read your flat file, rather than a problem with the code you're using to output it.

You're probably doing something like this, right?:
Code:
while(<FILE>) {
   my ($first, $second) = split(/=/, $_);
}

The problem there is that, with parameters, your URL contains the '=' sign, which is being used for splitting, so in the example above, $Link is going to be "
The solution is to limit the number of fields in the split to 2 (i.e. put everything before the first '=' as the first value returned and everything else, whether it contains '='s or not, into the second one), i.e.:
Code:
while(<FILE>) {
   my ($first, $second) = split(/=/, $_, 2);
}

Changing your split statement as above should sort it out.
 
Thanks isnnid,

I'm not using split but a regex and chomp
This is what I have right now
Code:
$Line =~ s/\s*=\s*/=/;
	chomp $line;

Thanks again
 
Hmm. All that code does is remove whitespace on either side of the '=' sign and take the newline off the end. Post the code where $Link and $Name are created.

Incidentally, a nicer way to print double quotes in an interpolated string (without having to escape them) is this:
Code:
print qq!<a href="$Link">$Name</a>!;
 
Sorry...

This is the regex I'm using right now
Code:
if ($Line =~ /^(.*)=(.*)$/) {
 
Using the split would be better I think but if you do want to use a regexp, you'll have to make the first capturing group non-greedy. '.*' matches zero or more characters but tries to match as many as possible (i.e. everything up until the last '=' sign. To make it non-greedy (i.e. match everything up until the first '=' sign, do this:
Code:
if ($Line =~ /^(.*?)=(.*)$/) {
 
Thank you very much ishnid. Really appreciated !!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top