Click here to get back home

1 string from 3, making replacements more perlish

 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
1 string from 3, making replacements more perlish StuPedaso 08-29-2006
Get Chitika Premium
Posted by StuPedaso on August 29, 2006, 5:55 pm
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 Andre Beausoleil on August 29, 2006, 6:16 pm
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 Paul Lalli on August 29, 2006, 6:23 pm
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 Dr.Ruud on August 29, 2006, 6:50 pm
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 DJ Stunks on August 29, 2006, 6:56 pm
Please log in for more thread options
StuPedaso wrote:
> I have 1 string made up of ones and zeros,
> a 2nd and 3rd of letters and number,
> and need to create a 4th where the 1's are successively pulled from 2,
> and the 1's from the 3rd.
>
> I can this do this in a QB/VB type way with
> $string1="001010110";
> $string2="a1bd3";
> $string3="0XY0";
>
> $l=0;$m=0;$p=0;
> $string4="";
>
> for $i (0..(length $string1)){
> $x=substr($string1,$l,1);$l++;
> if ($x==1)
> else
> }
> print $string4;
> #a10bXdY03
>
> Not very perlish
> Also I don't want to modify srting1, as I will be using it again after
> I modify 2 and 3.

what do y'all think of this:

#!/usr/bin/perl

use strict;
use warnings;

my $key_string = '001010110';
my $string_0 = 'a1bd3';
my $string_1 = '0XY0';

my %hash = (
        0 => [ split //, $string_0 ],
        1 => [ split //, $string_1 ],
);

my $result;
for my $i (split //, $key_string) {
        $result .= shift @{ $hash };
}

print "result: $result\n";

?

-jp


Similar ThreadsPosted
Making sure a string is valid money number November 27, 2005, 12:48 pm
/~/~/~/~/~/~/ Making a Six-Figure Income From Passive / Money Making Tips its FREEEE /~/~/~/~/~/~/ November 26, 2007, 3:58 pm
PerlCom Replacements December 7, 2004, 8:14 pm
Regular Expressions & replacements September 24, 2008, 12:42 pm
Isolate lines in a text file and perform replacements March 30, 2007, 2:16 pm
perlish way for ( 0 .. $n) , but downcounting August 14, 2008, 9:21 am
File edits in a Perlish way September 29, 2008, 1:08 pm
"Perlish Patterns" by Phil Crow August 24, 2004, 9:22 am
making graph December 7, 2008, 3:39 am
Help: making images with perl? November 27, 2004, 7:29 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap