Loading ...
Sorry, an error occurred while loading the content.
 

Re: [PBML] new member needs help!

Expand Messages
  • Jeff 'japhy' Pinyan
    ... split() is used to split up a string based on some pattern. If you have a string like I went to the store , you could do: my @words = split / s+/,
    Message 1 of 7 , Aug 30 7:07 AM
      On Aug 30, Krishnakant said:

      >1. I did not get the use of split function. Please give me some hint or
      >example as to how it is used and what is its application.

      split() is used to split up a string based on some pattern. If you have a
      string like "I went to the store", you could do:

      my @words = split /\s+/, $string;

      and get ("I", "went", "to", "the", "store") in @words. You can also split
      on an empty string, which gets you a list of the individual characters:

      my @chars = split //, "japhy"; # ('j', 'a', 'p', 'h', 'y')

      See 'perldoc -f split' for more details.

      >2. How do parameters or arguments work with a perl sub routine. I mean
      >how do we pass the arguments and get them back.

      (I'm not going to talk about prototypes.) Basically, the arguments to a
      function are just elements in a list, and you have access to that list via
      the @_ array in your function.

      foo(10, 20 .. 25);
      sub foo {
      my ($x, $y, $z) = @_;
      print "$x + $y + $z\n"; # 10 + 20 + 21
      }

      As you can see, I passed seven arguments, but I'm only using three of
      them, but Perl doesn't care.

      See 'perldoc perlsub' for more details.

      --
      Jeff "japhy" Pinyan japhy@... http://www.pobox.com/~japhy/
      RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
      ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
      <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
      [ I'm looking for programming work. If you like my work, let me know. ]
    Your message has been successfully submitted and would be delivered to recipients shortly.