Ask a Question related to PERL Beginners, Design and Development.
-
Ajit P Singh #1
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
-
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... -
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... -
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... -
'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... -
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 {... -
Rob Dixon #2
Re: RE:help on picking up key & values
Ajit P Singh wrote:
How is this '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..
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
-
Ajit P Singh #3
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:as>
> 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 valuesHow is this 'RE:help on picking up key & values'?> 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..
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
-
Rob Dixon #4
Re: RE:help on picking up key & values
Ajit P Singh wrote:
OK, but your original post said:> 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.
and I'm not sure how you want to 'do away' with them. They have> How can I do away with the hard coded keys?
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
-
R. Joseph Newton #5
Re: help on picking up key & values
"Singh, Ajit p" wrote:
Okay, how are the hash keys getting assigned?> 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";
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.
That should be easy enough. See below.>
>
> My problem is to get away with the hard coded values i.e
> /thus/axioss/serviceID:,/thus/axioss/supplierProduct:, and
> /thus/axioss/web/installationTelephoneNumber:
There should be very little question here of how to eliminate the hard-coded>
>
> 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
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.
Just throw away less of the information your program takes in while reading the> How can I do away with the hard coded keys?
file, and there should be no need for them.
Joseph
R. Joseph Newton Guest
-
R. Joseph Newton #6
Re: help on picking up key & values
"Singh, Ajit p" wrote:
Not really. An array of structs has no meaning in Perl directly, AFAIK. Perl> 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.
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
-
Ajit #7
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



Reply With Quote

