Professional Web Applications Themes

$_. and $_, - PERL Beginners

Hallo! Stupid question, but i am a perlbeginner! :-( What is the difference between $_. and $_, ?? Regards...

  1. #1

    Default $_. and $_,

    Hallo!
    Stupid question, but i am a perlbeginner! :-(
    What is the difference between $_. and $_, ??

    Regards

    E.Horn Guest

  2. #2

    Default Building an Array

    Real Perl newbie question...

    I have a script that retrieves a response using HTTP:Request and
    HTTP:Response. I get back a response in the content as a URLEncoded string.
    For example 'id=101&results=passed'

    I would like to take this response, and p it into an array where I can
    call each value by it's key name, for example:

    print 'My ID = %myarray['id']';
    print 'My Results = %myarray['results']';


    How can I do this?

    Thanks,
    Tom

    Thomas Guest

  3. #3

    Default Re: $_. and $_,

    On Wed, 13 Oct 2004 11:48:41 +0200, E.Horn wrote:
     
    Well, $_ is the default variable for a many perl constructs. eg in a
    foreach loop. The dot (.) operator is used for concatenation (i.e. joining
    of two strings into one). The comma (,) operator can be used in different
    ways. see parldoc perlop for more on these.

    So to answer your question $_. is incomplete because it's trying to
    concatentate $_ with something else (unknown); and $_, is also incomplete
    because it's dependent on its context. Post an example of each in code you
    need help with for more specific info. HTH

    Chris.
    Chris Guest

  4. #4

    Default Re: Building an Array

    On Wed, 13 Oct 2004 12:28:46 +0200, Thomas Drought wrote:
     

    Have a look at split. Type this at the command line:
    perldoc -f split
     
    ^^^^^^^^^^^^^^^^^^^

    This is incorrect. Array elements are accessed via an index number not
    a string and the '%' symbol is used to define a hash; '' is used to
    arrays. I think what you're after is a hash not an array:

    my %myhash = qw(id 101 results passed);

    print "My ID = $myhash{id}\n";
    print "My Results = $myhash{results}\n";

    HTH
    Chris.
    Chris Guest

  5. #5

    Default RE: Building an Array

    Thomas Drought <com> wrote:

    : Real Perl newbie question...
    :
    : I have a script that retrieves a response using HTTP:Request
    : and HTTP:Response. I get back a response in the content as a
    : URLEncoded string. For example 'id=101&results=passed'
    :
    : I would like to take this response, and p it into an
    : array where I can call each value by it's key name, for
    : example:

    Arrays use indexes (integers) to identify their individual
    values. Hashes use keys. You probably want a hash.

    : print 'My ID = %myarray['id']';
    : print 'My Results = %myarray['results']';

    Parsing is breaking something down into its component
    parts. You are printing here. Read 'perldata'. It is a file
    included in the standard perl distribution. It will help you
    with syntax. URI::URL and URI::QueryParam have functions to
    p queries.


    HTH,

    Charles K. Clarkson
    --
    Mobile Homes Specialist
    254 968-8328



    Charles Guest

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139