in reply to tagging question

If I understand your question properly...

$string = "il asdfasdfasdf"; $string =~ s/([\S]{2})//; $tag = "<$1>"; $string = $tag . "$string ". $tag

Would do what you're asking for. I'm sure a true perl master could condense that into 1-2 lines, but I'm just a little perl footsoldier right now...

Peace,
LassiLantar

Replies are listed 'Best First'.
Re^2: tagging question
by Ovid (Cardinal) on Jul 23, 2004 at 23:30 UTC

    I'm sure a true perl master could condense that into 1-2 lines.

    But a true Perl master would go for clarity over conciseness unless the circumstances dictate otherwise.

    Cheers,
    Ovid

    New address of my CGI Course.

      True, true. Again, I am outclassed =)

      Peace,
      LassiLantar

Re: tagging question
by b10m (Vicar) on Jul 23, 2004 at 23:58 UTC

    I'm pretty sure you can make this code shorter if you really want to, but I am curious why you chose to substitute all lines. That, to me, looks like a lot of useless hassle ;)

    Anyways, for the OP, my €0,02:

    while(<DATA>) { print "<$1>$1$2<$1>" if $_ =~ m|(\w{2})(.*)|; } __DATA__ il yadayadayada df yadayadayada
    --
    b10m

    All code is usually tested, but rarely trusted.
      <snappy comeback> Well, he said each line had a tag on the beginning of it, so I figured it would be extra to deal with checking whether it did. </snappy comeback>

      <real excuse> Didn't think of it =) </real excuse>

      Peace,
      LA

Re^2: tagging question
by beable (Friar) on Jul 24, 2004 at 01:16 UTC
    I must not be a true perl master, because I hacked on your program and it got BIGGER!
    #!/usr/bin/perl # you have to use strict and warnings unless you # have a really good reason not to. use strict; use warnings; my $string = "il asdfasdfasdf"; my $tag = ""; # use matching here instead of substitution # all of the string should appear in the output # also, don't need square brackets in match if ($string =~ m/(\S{2})/) { $tag = "<$1>"; } # you don't need to concatenate, just interpolate the lot $string = "$tag $string $tag"; print "string = $string\n"; __END__
      I must not be a true perl master, because I hacked on your program and it got BIGGER!

      Gwuahaha! I am superior! (read: I am too lazy to write in use strict/use warnings on PM). I agree with you, use strict and warnings are totally necessary. I'm so lazy I even sometimes try to circumvent use strict by redeclaring my variables in random places, but really they're improving the way I write code. (As is sparring with the monks).

      Peace,
      LassiLantar