Complex URL

Posted on 2006-04-07
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?
Question by:stakor
    LVL 39

    Expert Comment

    The & is a special character, and needs to be escaped when in double quotes:

    Depending on what is in the string, and if you need to interpolate variables, a different quote operator might be easier to use:'-''-%22-%22%22-%2f%2f-%60-%60%60-%3c%3c-escape-sequence-escape

    Author Comment

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

    Author Comment

    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?
    LVL 39

    Accepted Solution

    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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
    A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
    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…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now