help on picking up key & values

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default RE:help on picking up key & values

    Comrades,


    I have a function which takes up arguments as shown below:

    $str = "./place_order -t " .
    "/thus/axioss/serviceID:\"" . $self->{serviceID} . "\" " .
    "/thus/axioss/supplierProduct:\"" . $self->{supplierProduct} . "\" "
    ..
    "/thus/axioss/web/installationTelephoneNumber:\"" .
    $self->{installationTelephoneNumber} . "\n";

    My problem is to get away with the hard coded values i.e
    /thus/axioss/serviceID:,/thus/axioss/supplierProduct:, and
    /thus/axioss/web/installationTelephoneNumber:

    I am fetching the above arguments from a file which contains these values as
    shown below.

    /thus/axioss/serviceID:123456
    /thus/axioss/supplierProduct:BT IPStream 500
    /thus/axioss/web/installationTelephoneNumber:020837111663

    How can I do away with the hard coded keys?

    Thanks in advance..

    ----------------------------------------------------------------------------
    ----------------

    regards,

    Ajitpal Singh,
    Ajit P Singh Guest

  2. Similar Questions and Discussions

    1. Picking up where others left off
      Hi there, I've recently been employed as a junior web developer updating a website and intranet and i need a lot of help...I mentioned i knew php...
    2. Ray Picking with director
      Ok here is my problem...for picking purposes I need to shoot a ray that goes from my mouse pointer (using spriteSpaceToWorldSpace) on to screen...
    3. picking lingo
      HI, I'm finding it really hard to get to grips with picking lingo...been through many examples but can't seem to get it working. Could somebody...
    4. 'while' not picking up on first DB record
      Hello, Can anyone from the lists please tell me why this bit of code is not picking up on the first record in the database? If the 'id' I'm...
    5. picking up value in code behind
      "Scott Collens" <scottcollens@nospam.hotmail.com> wrote Scott, In the User Control, create a public property public string Username { get {...
  3. #2

    Default Re: RE:help on picking up key & values

    Ajit P Singh wrote:
    >
    > Comrades,
    >
    >
    > I have a function which takes up arguments as shown below:
    >
    > $str = "./place_order -t " .
    > "/thus/axioss/serviceID:\"" . $self->{serviceID} . "\" " .
    > "/thus/axioss/supplierProduct:\"" . $self->{supplierProduct} . "\" "
    > .
    > "/thus/axioss/web/installationTelephoneNumber:\"" .
    > $self->{installationTelephoneNumber} . "\n";
    >
    > My problem is to get away with the hard coded values i.e
    > /thus/axioss/serviceID:,/thus/axioss/supplierProduct:, and
    > /thus/axioss/web/installationTelephoneNumber:
    >
    > I am fetching the above arguments from a file which contains these values as
    > shown below.
    >
    > /thus/axioss/serviceID:123456
    > /thus/axioss/supplierProduct:BT IPStream 500
    > /thus/axioss/web/installationTelephoneNumber:020837111663
    >
    > How can I do away with the hard coded keys?
    >
    > Thanks in advance..
    How is this 'RE:help on picking up key & values'?

    It's not clear what your problem is. You need to

    - Open the file
    - Read its records
    - Close it
    - Build your string from the data read

    What can't you do?

    Rob



    Rob Dixon Guest

  4. #3

    Default RE: RE:help on picking up key & values

    Thanks Rob for your reply...

    My problem is :the values i pick up from is actually not a file.(Sorry about
    that)

    The values are stored as an array of structs as key value pairs i.e
    /thus/axioss/serviceID:123456
    /thus/axioss/supplierProduct:Test Stream 100
    /thus/axioss/web/installationTelephoneNumber:020837111663

    I hope i am being clear now.

    ----------------------------------------------------------------------------
    ----------------

    regards,

    Ajitpal Singh,




    -----Original Message-----
    From: Rob Dixon [mailto:rob@dixon.port995.com]
    Sent: 12 February 2004 20:53
    To: [email]beginners@perl.org[/email]
    Subject: Re: RE:help on picking up key & values


    Ajit P Singh wrote:
    >
    > Comrades,
    >
    >
    > I have a function which takes up arguments as shown below:
    >
    > $str = "./place_order -t " .
    > "/thus/axioss/serviceID:\"" . $self->{serviceID} . "\" " .
    > "/thus/axioss/supplierProduct:\"" . $self->{supplierProduct} . "\" "
    > .
    > "/thus/axioss/web/installationTelephoneNumber:\"" .
    > $self->{installationTelephoneNumber} . "\n";
    >
    > My problem is to get away with the hard coded values i.e
    > /thus/axioss/serviceID:,/thus/axioss/supplierProduct:, and
    > /thus/axioss/web/installationTelephoneNumber:
    >
    > I am fetching the above arguments from a file which contains these values
    as
    > shown below.
    >
    > /thus/axioss/serviceID:123456
    > /thus/axioss/supplierProduct:BT IPStream 500
    > /thus/axioss/web/installationTelephoneNumber:020837111663
    >
    > How can I do away with the hard coded keys?
    >
    > Thanks in advance..
    How is this 'RE:help on picking up key & values'?

    It's not clear what your problem is. You need to

    - Open the file
    - Read its records
    - Close it
    - Build your string from the data read

    What can't you do?

    Rob




    --
    To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
    For additional commands, e-mail: [email]beginners-help@perl.org[/email]
    <http://learn.perl.org/> <http://learn.perl.org/first-response>

    Ajit P Singh Guest

  5. #4

    Default Re: RE:help on picking up key & values

    Ajit P Singh wrote:
    > Thanks Rob for your reply...
    >
    > My problem is :the values i pick up from is actually not a file.(Sorry about
    > that)
    >
    > The values are stored as an array of structs as key value pairs i.e
    > /thus/axioss/serviceID:123456
    > /thus/axioss/supplierProduct:Test Stream 100
    > /thus/axioss/web/installationTelephoneNumber:020837111663
    >
    > I hope i am being clear now.
    OK, but your original post said:
    > How can I do away with the hard coded keys?
    and I'm not sure how you want to 'do away' with them. They have
    to come from somewhere, and the obvious place is something like
    a config file. Is that what you mean?

    Ah, perhaps light dawns?

    Does this do something like what you want?

    (BTW it helps to always use single quotes unless you specifically
    want to interpolate variables or control characters)

    HTH,

    Rob



    my $self = {
    serviceID => '123456',
    supplierProduct => 'BT IPStream 500',
    installationTelephoneNumber => '020837111663',
    };

    my $str = './place_order -t';

    for (qw|
    /thus/axioss/serviceID
    /thus/axioss/supplierProduct
    /thus/axioss/web/installationTelephoneNumber |) {

    my ($key) = /(\w+)$/;
    $str .= qq| $_:"$self->{$key}"|;
    }

    $str .= "\n";

    print $str;

    **OUTPUT

    ../place_order -t /thus/axioss/serviceID:"123456" /thus/axioss/supplierProduct:"BT IPStream 500"
    /thus/axioss/web/installationTelephoneNumber:"020837111663"


    Rob Dixon Guest

  6. #5

    Default Re: help on picking up key & values

    "Singh, Ajit p" wrote:
    > Comrades,
    >
    > I have a function which takes up arguments as shown below:
    >
    > $str = "./place_order -t " .
    > "/thus/axioss/serviceID:\"" . $self->{serviceID} . "\" " .
    > "/thus/axioss/supplierProduct:\"" . $self->{supplierProduct} . "\" "
    > .
    > "/thus/axioss/web/installationTelephoneNumber:\"" .
    > $self->{installationTelephoneNumber} . "\n";
    Okay, how are the hash keys getting assigned?

    The code above shows you using the values of these hash elements, but we don't
    see how the value get into them. That is the place where you probably want to
    make changes to eliminate the need for these hard-coded values.
    >
    >
    > My problem is to get away with the hard coded values i.e
    > /thus/axioss/serviceID:,/thus/axioss/supplierProduct:, and
    > /thus/axioss/web/installationTelephoneNumber:
    That should be easy enough. See below.
    >
    >
    > I am fetching the above arguments from a file which contains these values as
    > shown below.
    >
    > /thus/axioss/serviceID:123456
    > /thus/axioss/supplierProduct:BT IPStream 500
    > /thus/axioss/web/installationTelephoneNumber:020837111663
    There should be very little question here of how to eliminate the hard-coded
    values--don't use them.

    If your file already contains the key-value pairs shown, you should capture them
    into variables as you load them. As a matter of fact it looks like you had to
    pick them apart to get your hash keys. Furthermore, you must have extracted all
    keys the same way, by removing the base directory from the string.
    Unfortunately it is not the same base directory in each case. This means that
    you will probably have to store the base directory strings for each key,
    possibly by keeping those, along with the value extracted, in an anonymous hash,
    and stroing a reference to the hash for each key.

    Something about the structure of the key value pairs strikes me wierd, though.
    What does that arrangement actually mean.

    It looks like you are storing filenames as keys for the values. Or are those
    Registry-type keys? In iether case, the operations on the base path should be
    about the same. I just would not see the sense in using filenames as hash keys.


    > How can I do away with the hard coded keys?
    Just throw away less of the information your program takes in while reading the
    file, and there should be no need for them.

    Joseph

    R. Joseph Newton Guest

  7. #6

    Default Re: help on picking up key & values

    "Singh, Ajit p" wrote:
    > Thanks Rob for your reply...
    >
    > My problem is :the values i pick up from is actually not a file.(Sorry about
    > that)
    >
    > The values are stored as an array of structs as key value pairs i.e
    > /thus/axioss/serviceID:123456
    > /thus/axioss/supplierProduct:Test Stream 100
    > /thus/axioss/web/installationTelephoneNumber:020837111663
    >
    > I hope i am being clear now.
    Not really. An array of structs has no meaning in Perl directly, AFAIK. Perl
    doesn't use structs. How are these values stored? How do you get them into
    Perl. Where do you get the values when you discuss them? Please, instead of
    describing this in terms of programming structures, tell us what you actually
    have to work with coming in, and what you hope to get out of it. What does each
    identifier mean, and where does the string come from?

    It could be that having a data file with these keys and values stored in it
    would be a good idea. But what are they? The coding part will probably come
    very simply if you can answer this question clearly. Using technical language
    incorrectly will not get you closer to your goal

    Keep it as simple as possible. Describe real-world situations in plain language
    first. This can then serve as a valuable guide to come back to when code and
    coding structures get mixed up. It's what we call the reality check or sanity
    test. Once your description makes sense in plain language, the coding part
    generally is relatively straightforward. I think your problem could be resolved
    quite simply, if you can refrain from injecting complication into it.

    Joseph


    R. Joseph Newton Guest

  8. #7

    Default RE: help on picking up key & values

    Joseph,

    Let me try and explain.
    i have a perl script place_order which takes arguments as below:

    1. ./place_order -t
    /thus/axioss/serviceID:123
    /thus/axioss/supplierProduct:TestStream 500
    /thus/axioss/web/installationTelephoneNumber:112237111663 etc

    2. I have a source as a hash of key value pairs as in :

    /thus/axioss/serviceID:123
    /thus/axioss/supplierProduct:TestStream 500
    /thus/axioss/web/installationTelephoneNumber:112237111663

    3. All I need to do is call the script in 1. and pass these values..Pls note
    that what i have in 2. is not a file.
    Its a message structure with each line as key value pairs.

    4. I dont have a control of either the target script i.e place_order or the
    source as in 2.

    5.My code needs to pick up this key valuse and invoke the target script.

    Thanks for u r time.

    ----------------------------------------------------------------------------
    ----------------

    regards,

    Ajitpal Singh,


    -----Original Message-----
    From: R. Joseph Newton [mailto:org]
    Sent: 13 February 2004 23:56
    To: Singh, Ajit p
    Cc: 'Rob Dixon'; org
    Subject: Re: help on picking up key & values


    "Singh, Ajit p" wrote:
     
    about 

    Not really. An array of structs has no meaning in Perl directly, AFAIK.
    Perl
    doesn't use structs. How are these values stored? How do you get them
    into
    Perl. Where do you get the values when you discuss them? Please, instead
    of
    describing this in terms of programming structures, tell us what you
    actually
    have to work with coming in, and what you hope to get out of it. What does
    each
    identifier mean, and where does the string come from?

    It could be that having a data file with these keys and values stored in it
    would be a good idea. But what are they? The coding part will probably
    come
    very simply if you can answer this question clearly. Using technical
    language
    incorrectly will not get you closer to your goal

    Keep it as simple as possible. Describe real-world situations in plain
    language
    first. This can then serve as a valuable guide to come back to when code
    and
    coding structures get mixed up. It's what we call the reality check or
    sanity
    test. Once your description makes sense in plain language, the coding part
    generally is relatively straightforward. I think your problem could be
    resolved
    quite simply, if you can refrain from injecting complication into it.

    Joseph

    Ajit Guest

Posting Permissions

  • You may not post new threads
  • You may 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