Normalize case on the months. Either uc @months (say, with map) or $t{lc $1}
in the substitution.

On Wed, Jul 27, 2011 at 12:18 PM, Avishalom Shalit <[email protected]>wrote:

> well, here's another conundrum ,
> $t{$1}
> $t{"$1"}
> and event
> $t{"OCT"}
>
> don't work
>
> $t gets parsed as a scalar  (even with use strict; , (inside
> "BEGIN{}", am I doing this right? ))
> to get it to work i had to use $a = \%t,
> $a->{"OCT"}
>
> any insights?
>  (except stop using one-liners?)
>
> -- vish
>
>
>
>
>
> On 26 July 2011 19:30, Gaal Yahas <[email protected]> wrote:
> > Change the substitution to use
> >   $t{"$1"}
> >
> > instead of
> >   $t{\1}
> > In general you should avoid sed-style backreferences in substitutions.
> > BTW whenever things are acting up in Perl the first thing you should do
> is
> > turn on strict and warnings. This is the case in one-liners, too.
> >   $ perl -wle 'print oct'
> >   Use of uninitialized value $_ in oct at -e line 1.
> >   0
> >
> >
> > On Tue, Jul 26, 2011 at 9:16 PM, Avishalom Shalit <[email protected]>
> > wrote:
> >>
> >> yes, it was a nasty one,
> >>
> >>  echo 'a'b'c'
> >> abc
> >>
> >>
> >> or more to the point
> >>
> >>  echo 'a a     a' b b      b 'c c      c'
> >> a a     a b b b c c      c
> >>
> >>
> >> ---
> >> also thanks
> >> qw is indeed the good solution,
> >>
> >> ---
> >>
> >> but while I am on the air,
> >> one more question,
> >>
> >> this was part of a preprocessing script to change dates into a nicer
> >> numerical format (quicker on large files than handling text in matlab)
> >>
> >> inside the loop i had
> >> s/(?<=X)(...)(?=X)/$t{\1}/e
> >>
> >> but that doesn't work
> >> it gives
> >> SCALAR(0x105354f8)
> >> after wasting too many minutes, i fell back on matlab,
> >>
> >>
> >> but let me leave this open
> >> how could i get this to work,
> >> (or conversely what would you do to change 11-JUN-2011 to 11-6-2011 etc.
> )
> >>
> >> -- vish
> >>
> >>
> >>
> >>
> >>
> >> On 26 July 2011 19:05, Gaal Yahas <[email protected]> wrote:
> >> > Sorry, I meant the *single* quotes never reached perl.
> >> >
> >> > On Tue, Jul 26, 2011 at 9:04 PM, Gaal Yahas <[email protected]> wrote:
> >> >>
> >> >> The double quotes never reached perl. In both cases, you are
> protecting
> >> >> your oneliner from your shell with single quotes, so when you reached
> >> >> 'jan',
> >> >> the "first" delimiter around that actually stopped shellquoting.
> >> >> To get around this kind of thing use Perl's flexible quote operators.
> >> >> Eg.,
> >> >> perl -MData::Dumper -e '@months = qw(jan feb mar apr ....);    ...and
> >> >> so
> >> >> on'
> >> >>
> >> >> On Tue, Jul 26, 2011 at 8:47 PM, Avishalom Shalit <
> [email protected]>
> >> >> wrote:
> >> >>>
> >> >>> the difference is the double quotes in october.
> >> >>>
> >> >>>
> >> >>> -----
> >> >>>
> >> >>>
> >> >>> $ perl -MData::Dumper -e
> >> >>>
> >> >>>
> >> >>>
> '@months=('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');@t{@months
> }=1..12;print
> >> >>> Dumper(\%t)'
> >> >>> $VAR1 = {
> >> >>>          'feb' => 2,
> >> >>>          'may' => 5,
> >> >>>          'mar' => 3,
> >> >>>          'dec' => 12,
> >> >>>          'jan' => 1,
> >> >>>          'aug' => 8,
> >> >>>          'sep' => 9,
> >> >>>          '0' => 10,
> >> >>>          'jun' => 6,
> >> >>>          'nov' => 11,
> >> >>>          'apr' => 4,
> >> >>>          'jul' => 7
> >> >>>        };
> >> >>>
> >> >>> $ perl -MData::Dumper -e
> >> >>>
> >> >>>
> >> >>>
> '@months=('jan','feb','mar','apr','may','jun','jul','aug','sep',"oct",'nov','dec');@t{@months
> }=1..12;print
> >> >>> Dumper(\%t)'
> >> >>> $VAR1 = {
> >> >>>          'feb' => 2,
> >> >>>          'may' => 5,
> >> >>>          'mar' => 3,
> >> >>>          'dec' => 12,
> >> >>>          'jan' => 1,
> >> >>>          'aug' => 8,
> >> >>>          'sep' => 9,
> >> >>>          'jun' => 6,
> >> >>>          'nov' => 11,
> >> >>>          'apr' => 4,
> >> >>>          'oct' => 10,
> >> >>>          'jul' => 7
> >> >>>        };
> >> >>>
> >> >>>
> >> >>> -- vish
> >> >>> _______________________________________________
> >> >>> Perl mailing list
> >> >>> [email protected]
> >> >>> http://mail.perl.org.il/mailman/listinfo/perl
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >> Gaal Yahas <[email protected]>
> >> >> http://gaal.livejournal.com/
> >> >
> >> >
> >> >
> >> > --
> >> > Gaal Yahas <[email protected]>
> >> > http://gaal.livejournal.com/
> >> >
> >> > _______________________________________________
> >> > Perl mailing list
> >> > [email protected]
> >> > http://mail.perl.org.il/mailman/listinfo/perl
> >> >
> >> _______________________________________________
> >> Perl mailing list
> >> [email protected]
> >> http://mail.perl.org.il/mailman/listinfo/perl
> >
> >
> > --
> > Gaal Yahas <[email protected]>
> > http://gaal.livejournal.com/
> >
> > _______________________________________________
> > Perl mailing list
> > [email protected]
> > http://mail.perl.org.il/mailman/listinfo/perl
> >
> _______________________________________________
> Perl mailing list
> [email protected]
> http://mail.perl.org.il/mailman/listinfo/perl
>



-- 
Gaal Yahas <[email protected]>
http://gaal.livejournal.com/
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to