Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Perl gem

Perl gem

Scheduled Pinned Locked Moved The Weird and The Wonderful
perlrubydata-structures
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bulg
    wrote on last edited by
    #1

    I know you don't get these very often, so please enjoy :). And hi to everyone - forums look great these days.

    my $select = "";
    my (@fields) = ("field1", "field2", "field3", "field4", "field5", "field6", "field7", "field8", "field9", "field10", "field11", "field12", "field13", "field14", "field15", "field16", "field17", "field18");
    foreach my $f (@fields)
    {
        $select .= "$f,";
    }
    chop $select;
    

    For those unfamiliar, @name= array variable, $name = scalar variable. 'chop' is interpreted as a function call with the intentional side effect of removing the last character from the scalar you pass it. As a bonus, plaintext strings surrounded by double quotes must be parsed by the interpreter (this is Perl) and variable names within them are replaced with values.

    B Kornfeld Eliyahu PeterK J 3 Replies Last reply
    0
    • B bulg

      I know you don't get these very often, so please enjoy :). And hi to everyone - forums look great these days.

      my $select = "";
      my (@fields) = ("field1", "field2", "field3", "field4", "field5", "field6", "field7", "field8", "field9", "field10", "field11", "field12", "field13", "field14", "field15", "field16", "field17", "field18");
      foreach my $f (@fields)
      {
          $select .= "$f,";
      }
      chop $select;
      

      For those unfamiliar, @name= array variable, $name = scalar variable. 'chop' is interpreted as a function call with the intentional side effect of removing the last character from the scalar you pass it. As a bonus, plaintext strings surrounded by double quotes must be parsed by the interpreter (this is Perl) and variable names within them are replaced with values.

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      That is, he creates one big string containing the values of $field1 to $field18 separated by a comma?

      M 1 Reply Last reply
      0
      • B bulg

        I know you don't get these very often, so please enjoy :). And hi to everyone - forums look great these days.

        my $select = "";
        my (@fields) = ("field1", "field2", "field3", "field4", "field5", "field6", "field7", "field8", "field9", "field10", "field11", "field12", "field13", "field14", "field15", "field16", "field17", "field18");
        foreach my $f (@fields)
        {
            $select .= "$f,";
        }
        chop $select;
        

        For those unfamiliar, @name= array variable, $name = scalar variable. 'chop' is interpreted as a function call with the intentional side effect of removing the last character from the scalar you pass it. As a bonus, plaintext strings surrounded by double quotes must be parsed by the interpreter (this is Perl) and variable names within them are replaced with values.

        Kornfeld Eliyahu PeterK Offline
        Kornfeld Eliyahu PeterK Offline
        Kornfeld Eliyahu Peter
        wrote on last edited by
        #3

        He made a perfect example of code reuse! Spared 17 times the $ sign!!!

        I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

        "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

        1 Reply Last reply
        0
        • B bulg

          I know you don't get these very often, so please enjoy :). And hi to everyone - forums look great these days.

          my $select = "";
          my (@fields) = ("field1", "field2", "field3", "field4", "field5", "field6", "field7", "field8", "field9", "field10", "field11", "field12", "field13", "field14", "field15", "field16", "field17", "field18");
          foreach my $f (@fields)
          {
              $select .= "$f,";
          }
          chop $select;
          

          For those unfamiliar, @name= array variable, $name = scalar variable. 'chop' is interpreted as a function call with the intentional side effect of removing the last character from the scalar you pass it. As a bonus, plaintext strings surrounded by double quotes must be parsed by the interpreter (this is Perl) and variable names within them are replaced with values.

          J Offline
          J Offline
          Jorgen Andersson
          wrote on last edited by
          #4

          I was half expecting a musical reference... :doh:

          Wrong is evil and must be defeated. - Jeff Ello[^]

          R 1 Reply Last reply
          0
          • J Jorgen Andersson

            I was half expecting a musical reference... :doh:

            Wrong is evil and must be defeated. - Jeff Ello[^]

            R Offline
            R Offline
            Richard Deeming
            wrote on last edited by
            #5

            A musical reference, and no code[^]? ;P


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            1 Reply Last reply
            0
            • B Bernhard Hiller

              That is, he creates one big string containing the values of $field1 to $field18 separated by a comma?

              M Offline
              M Offline
              Matt T Heffron
              wrote on last edited by
              #6

              Not quite... the "$f," only interpolates the value of the f scalar... so the result is the single string: 'field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11,field12,field13,field14,field15,field16,field17,field18' Seriously pointless!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups