I isolated the problem from my previous post to this behavior, which I think is a bit problematic -- i.e. split is doing more than is should, IMO. Off hand, not seeing the forest for the trees, I'm not sure how to get split to leave the strings alone and not treat them as numbers.

The following demonstrates the problem:

n> perl -E 'use P; my $fmt="prod\t006\t2.13\tx86_64\trpm";P $fmt; my $str=P $fmt;P "str=\"$str\""; my @flds=split /\t/,"$str"; foreach (@flds) { Pe "%s \x83", "$_"; } P " "; ' prod 006 2.13 x86_64 rpm str="prod 006 2.13 x86_64 rpm" prod 6 2.13 x86_64 rpm
If I put the params in an array, the 006 collapses right off the bat:
perl -E 'use P; my $fmt=["%s\t%s\t%s\t%s\trpm","prod", "006", "2.13", "x86_64", "rpm"] +; P "%s", $fmt; # already converted ' ["%s %s %s %s rpm","prod",6,2.13,"x86_64","rpm"]
Using qw the tabs don't expand (so the split doesn't work anyway), but the 6 still collapses:
> perl -E 'use P; my $fmt=[qw(%s\t%s\t%s\t%s\t%s prod 006 2.13 x86_64 rpm)]; P "%s", $fmt; # already converted before fmt my $str=P @$fmt; P "str=\"$str\""; my @flds=split "\t","$str"; Pe "(%s) \x83", "$_" foreach @flds; P " ";' ["%s\t%s\t%s\t%s\t%s","prod",6,2.13,"x86_64","rpm"] str="prod\t6\t2.13\tx86_64\trpm" (prod\t6\t2.13\tx86_64\trpm)
Quirky combo to hack it:
> perl -E 'use P; my $fmt=["%s\t%s\t%s\t%s\t%s", qw( prod "006" "2.13" x86_64 rpm)]; P "%s", $fmt; # already converted before fmt my $str=P @$fmt; P "str=\"$str\""; my @flds=split "\t","$str"; Pe "(%s) \x83", "$_" foreach @flds; P " ";' ["%s %s %s %s %s","prod",""006"",""2.13"","x86_64"," +rpm"] str="prod "006" "2.13" x86_64 rpm" (prod) ("006") ("2.13") (x86_64) (rpm)
But running that in the prog I ended up with:
Recycling 1 duplicates...(cannot stat, already deleted?) path=/Share/s +use/distribution/12.1/repo/oss/suse/test2/smugbatch-"006"-"2.1.3".x86 +_64.rpm, dev=(undef)
!!!! Guess I'll keep poking at it... there's gotta be a way... but dang if this isn't harder than it should be...

p.s. maybe I'll just toss an eval on that final string and forget figuring out how to quote it...urg...


In reply to is split suppose to drop 0's from strings? by perl-diddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.