Click here to get back home

string matching inside file and save in a variable

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
string matching inside file and save in a variable andy 06-06-2007
Posted by andy on June 6, 2007, 5:16 am
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by Gunnar Hjalmarsson on June 6, 2007, 6:05 am
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Similar ThreadsPosted
How do i get the charactors inside the ( ) from a string variable March 25, 2006, 2:46 pm
Using a variable in a matching string November 21, 2006, 1:18 pm
save to file problem November 23, 2005, 8:50 pm
save image from url to file - how to? June 21, 2006, 9:49 am
Stupid Q: Read complete file into variable or string July 9, 2006, 7:50 am
Help with variable with regex inside. December 4, 2006, 2:05 am
Variable containing name of function inside a package June 27, 2005, 5:10 pm
use one subroutine's variable value in another subroutine inside a module. April 26, 2007, 9:28 am
Using one methods variable value in another method inside a module April 29, 2007, 9:04 am
Help with Pattern matching. Matching multiple lines from while reading from a file. May 2, 2007, 11:37 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap