[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Complex URL

Posted on 2006-04-07
4
Medium Priority
?
407 Views
Last Modified: 2012-06-27
I am attempting to feed a complex url (lots of "&"'s and "="'s) to wget, through a system call. I have a feeling that it is a problem with getting perl to send the string to the shell (running on Linux). When I change the command to echo instead of wget, I get:

Can't modify constant item in scalar assignment at <line_number>

The url consists of a first part, which is always the same. The second part is being read from a text file, and then I am appending it to the first half with the $_ variable in a while loop.

Any thoughts?
0
Comment
Question by:stakor
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 16401177
The & is a special character, and needs to be escaped when in double quotes:
$url="www.something.com/page.cgi?a=1\&b=2\&c=3";

Depending on what is in the string, and if you need to interpolate variables, a different quote operator might be easier to use:
http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators-operator%2c-quote-operator%2c-quote-like-q-qq-qx-qw-m--qr-s-tr-'-''-%22-%22%22-%2f%2f-%60-%60%60-%3c%3c-escape-sequence-escape
0
 

Author Comment

by:stakor
ID: 16401212
Ok, I figured out it is the "&" being fed to the wget command. I need to change all occurences of "&" in my string to "\&".
0
 

Author Comment

by:stakor
ID: 16401229
Thanks Adam314. I think the fix would be to do a search and replace on those characters ("&"). Could you post a seach and replace command?
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 2000 total points
ID: 16401292
Are there any & anywhere else in your code?  If so, you wouldn't want to do a search/replace on all of those (eg: if($a && $b)   )
I would suggest using the search/replace function of your editor, and review every replace first - to make sure only those you want replaced get replaced.

If you are sure you want to replace every & though, you could use sed:

sed -e 's/\&/\\\&/g' filename
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question