On 8/3/07, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote:
> Chas Owens wrote:
> > Okay, I will concede that, but there is generally a character that is
> > safe (usually the character the line was split on).  In this case
> >     $hash{join ',', @cdr[2,3,6,7]} = $line;
> > is safe due to the fact that @cdr was created using split /,/, so I
> > would recommend that over a multidimensional hash.
> >
>
> Safe until the format of the input changes.  If, for example, you tried
> this on a CSV (comma-separated-values) file, it would fail since
> commas can be escaped.  That is why $; is set to the default value
> of ASCII \034, a non-printable control character that is unlikely to
> appear in text.  But if you have your heart set on a composite key:
>
> {
>   local( $" ) = $;;
>   $hash{"@cdr[2,3,6,7]"} = $line;
> }
snip

They composite key breaks at the same time as the split, so both would
need to be modified and \034 isn't any safer.  It all depends on your
data.  Also, the short cut of using "@cdr[2,3,6,7]" is pointless if
you aren't going to use the default value of $", it is shorter to type

$hash{join "\034", @cdr[2,3,6,7]} = $line;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to