Wot Does this mean?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thanawala27
    New Member
    • Mar 2007
    • 68

    Wot Does this mean?

    hey can anyoen tell me wot does this mean

    $name =~ s/\n.+//g;
    $name =~ s/\s+/_/g;
    $name =~ s/^_//;
    $name =~ s/_$//;
    $name =~ s/[^a-zA-Z0-9_]+//g;
    $name =~ s/^[0-9_]+//g;


    and this one too..
    what will be the value of $item in the following cases:

    $item = $item . "" . $_;


    $item = $item . "," . $Arguments{"cna me"}; [ cname is a textbox ]


    Any help is apreciated

    Thanks,

    Ravi
  • arne
    Recognized Expert Contributor
    • Oct 2006
    • 315

    #2
    Try http://perldoc.perl.org/. The links on the left (esp. Functions, Operators, Special variables) should explain all you need to understand the code you posted :)

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      well, this stuff:

      Code:
      $name =~ s/\n.+//g;
      $name =~ s/\s+/_/g;
      $name =~ s/^_//;
      $name =~ s/_$//;
      $name =~ s/[^a-zA-Z0-9_]+//g;
      $name =~ s/^[0-9_]+//g;
      means someone doesn't understand how to write regular expressions very well. The other suff is concatenation, or the joining of strings together to make a new string.

      Code:
      $foo = 'foo';
      $bar = 'bar';
      $foo = $foo . $bar;
      print $foo; [prints "foobar"]
      this:

      Code:
      $foo .= $bar;
      is the same as:

      Code:
      $foo = $foo . $bar;
      this line shows the coder has limited understanding of the "." operator

      Code:
      $item = $item . "" . $_;
      could be written as:

      Code:
      $item .= $_;

      Comment

      • rock7799
        New Member
        • May 2007
        • 4

        #4
        $name =~ s/\n.+//g; this means substitute newline and next all lines with nothing.(g for globaly)

        $name =~ s/\s+/_/g; this means substitute mulitple spaces with and underscore.
        $name =~ s/^_//; this means substitute word or line starts with(^) underscore to nothing
        $name =~ s/_$//; default variable value to nothing
        $name =~ s/[^a-zA-Z0-9_]+//g; word with char numbers underscore and following occurance to nothing

        $name =~ s/^[0-9_]+//g;
        numbers and underscore to nothing

        and this one too..
        what will be the value of $item in the following cases:

        $item = $item . "" . $_; appends default variable to $item


        $item = $item . "," . $Arguments{"cna me"}; [ cname is a textbox ]

        appends comma and a hash value to $item

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          Originally posted by rock7799
          $name =~ s/\n.+//g; this means substitute newline and next all lines with nothing.(g for globaly)

          $name =~ s/\s+/_/g; this means substitute mulitple spaces with and underscore.
          $name =~ s/^_//; this means substitute word or line starts with(^) underscore to nothing
          $name =~ s/_$//; default variable value to nothing
          $name =~ s/[^a-zA-Z0-9_]+//g; word with char numbers underscore and following occurance to nothing

          $name =~ s/^[0-9_]+//g;
          numbers and underscore to nothing

          and this one too..
          what will be the value of $item in the following cases:

          $item = $item . "" . $_; appends default variable to $item


          $item = $item . "," . $Arguments{"cna me"}; [ cname is a textbox ]

          appends comma and a hash value to $item

          Some of your explanations are not correct.

          Comment

          Working...