okamoto@hpcc01.HP.COM (Jeff Okamoto) (08/14/90)
I got around this problem by doing a grep, but it's puzzling. Larry,
can you confirm if this is a programming error or a bug?
(I'm at patchlevel 18.)
#!/usr/bin/perl
$i = 0;
@a = ( "", "", "Hello" );
while($a[0] == "" && $i < 100) {
shift(@a);
$i++;
}
print "Found it at position $i\n";
--
\ oo The New Number Who,
\____|\mm Jeff Okamoto
//_//\ \_\ HP Corporate Computing & Services
/K-9/ \/_/ okamoto@hpccc.corp.hp.com
/___/_____\ ..!hplabs!hpccc!okamoto
----------- (415) 857-6236
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (08/14/90)
In article <12150004@hpcc01.HP.COM> okamoto@hpcc01.HP.COM (Jeff Okamoto) writes:
: #!/usr/bin/perl
:
: $i = 0;
: @a = ( "", "", "Hello" );
:
: while($a[0] == "" && $i < 100) {
: shift(@a);
: $i++;
: }
: print "Found it at position $i\n";
Change the == to eq and it should work better. A -w would have
pointed this out, by the way.
Larry
okamoto@hpcc01.HP.COM (Jeff Okamoto) (08/16/90)
Well, so I got caught by one of the "Ten Most Common Perl Mistakes". This one's a little more strange. I'm trying to unpack a structure that contains binary data. My template is like this: $STRLEN = 20; $struct = "l i i a$STRLEN"; After read'ing a number of bytes and unpacking, the variable that corresponds to the "a" above doesn't get filled with nulls, it gets filled with spaces, which I have verified using index. Using "A" instead of "A" yields identical results. Could this be a problem with either read or unpack? P.S. I'm at patchlevel 18. P.P.S. Using the -w flag shows no problems.
okamoto@hpcc01.HP.COM (Jeff Okamoto) (08/16/90)
okamoto@hpcc01.HP.COM (That's me!) said: > I'm trying to unpack a structure that contains binary data. My > template is like this: $STRLEN = 20; $struct = "l i i a$STRLEN"; > After read'ing a number of bytes and unpacking, the variable that > corresponds to the "a" above doesn't get filled with nulls, it gets > filled with spaces, which I have verified using index. Using "A" > instead of "A" yields identical results. After further experimentation, it looks as though I may be using index incorrectly. This is what I am using now: $i = index($q_dest, '\000'); Perl -w doesn't complain, but $i always returns -1. What am I doing wrong here? Jeff
merlyn@iwarp.intel.com (Randal Schwartz) (08/17/90)
In article <12150006@hpcc01.HP.COM>, okamoto@hpcc01 (Jeff Okamoto) writes: | After further experimentation, it looks as though I may be using index | incorrectly. This is what I am using now: | | $i = index($q_dest, '\000'); | | Perl -w doesn't complain, but $i always returns -1. What am I doing | wrong here? Maybe it will be apparent after running the following fragment: $q_dest = "abc\000def"; print index($q_dest,'\000'),"\n"; print index($q_dest,"\000"),"\n"; Backslashes are not interpreted insided single-quoted strings. $_="3xJ2yu0qs7!t a2Un9Po5Vt3#he9Pr5M 3EP8(e5Mr6Xl2Q ha7&ck0#er,";s/\d.//g;print -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/