RE: has key/value pairs

2006-05-03 Thread Charles K. Clarkson
Smith, Derek wrote:

: I need to create a hash with a key/value pair as text:nontext
: like so:
: savecrash as the key and 1 as the value
: 
: savecrash_dir as the key and /var/adm/crash as the value.
: 
: for (;SC;) {
: 
: if ( /(?i)savecrash=/ || /(?i)savecrash_dir=\W+\w+/ ) {
: 
: chomp;

  my( $key, $value ) = split /=/;
  $vg{$key} = $value;

: $vg{$_}++;

Delete that line. You can read more about the split()
function in the perl documentation.

: 
: }
: 
:   }


HTH,

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



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: has key/value pairs

2006-05-03 Thread Smith, Derek

-Original Message-
From: Charles K. Clarkson [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 03, 2006 4:10 PM
To: 'Perl Beginners'
Subject: RE: has key/value pairs

Smith, Derek wrote:

: I need to create a hash with a key/value pair as text:nontext
: like so:
: savecrash as the key and 1 as the value
: 
: savecrash_dir as the key and /var/adm/crash as the value.
: 
: for (;SC;) {
: 
: if ( /(?i)savecrash=/ || /(?i)savecrash_dir=\W+\w+/ ) {
: 
: chomp;

  my( $key, $value ) = split /=/;
  $vg{$key} = $value;

: $vg{$_}++;

Delete that line. You can read more about the split()
function in the perl documentation.

: 
: }
: 
:   }


*

Excellent... thank you. Before sending the email question, I was trying
to use split to get rid of that and could not get it to work as I was
using
code

For (FH)
  If (/pattern/) {
   split /\=/ ,$_ /;
   $vg{$_}++  
  }
}
/code

Why didn't this work?

derek

Cardinal Health -- Working together. For life. (sm)
_

This message is for the designated recipient only and may contain privileged, 
proprietary, or otherwise private information. If you have received it in 
error, please notify the sender immediately and delete the original. Any other 
use of the email by you is prohibited.

Dansk - Deutsch - Espanol - Francais - Italiano - Japanese - Nederlands - Norsk 
- Portuguese - Svenska: www.cardinalhealth.com/legal/email

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: has key/value pairs

2006-05-03 Thread Charles K. Clarkson
Smith, Derek wrote:

: Excellent... thank you. Before sending the email question, I
: was trying to use split to get rid of that and could not get
: it to work as I was using
: code
: 
: For (FH)
:   If (/pattern/) {
:split /\=/ ,$_ /;
:$vg{$_}++
:   }
: }
: /code
: 
: Why didn't this work?

Because it is wrong on so many levels. Seriously, assuming
the capitalization of for and if are typos, you can't just
add a slash / wherever you want to and expect perl to know
why. Assuming that trailing slash is also a typo, And you
really meant this ...

for (FH)
if (/pattern/) {
split /\=/, $_;
$vg{$_}++
}
}

... then there are still problems. First split() returns
a list of values, but you are not capturing that list. I think
that split() defaults to placing its values in @_, but you are
not accessing that here and it is deprecated.

All the work is being done in $vg{$_}++ which ignores
the split() and increments the value associated with the key
in $_. That one of those key/value pairs happens to be correct
is just coincidence.


HTH,

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



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: has key/value pairs

2006-05-03 Thread JupiterHost.Net

Excellent... thank you. Before sending the email question, I was trying
to use split to get rid of that and could not get it to work as I was
using
code

For (FH)
  If (/pattern/) {
   split /\=/ ,$_ /;
   $vg{$_}++  
  }

}
/code

Why didn't this work?



a) its invalid code, there are ton of things that'd keep it from even 
compiling let all doing the logic you want.


b) actually using the code and resolving the most obvious errors 
instead of saying as I was using which you clearly never had run or 
you'd have gotten compilation errors instead of results that were not 
your goal


Seriously Derek, you've been around this list long enough to know how to 
ask questions and posting this code does not return what I want when 
the code doesn't even compile is a waste of time and resources and is 
actually a lie which I;m sure no one appreciates.


I don't mean to be rude but please try to use a little common sense and 
effort. help people help you :)


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: has key/value pairs

2006-05-03 Thread Chad Perrin
On Wed, May 03, 2006 at 04:41:19PM -0500, Charles K. Clarkson wrote:
 Smith, Derek wrote:
 
 : Excellent... thank you. Before sending the email question, I
 : was trying to use split to get rid of that and could not get
 : it to work as I was using
 : code
 : 
 : For (FH)
 :   If (/pattern/) {
 :split /\=/ ,$_ /;
 :$vg{$_}++
 :   }
 : }
 : /code
 : 
 : Why didn't this work?
 
 Because it is wrong on so many levels. Seriously, assuming
 the capitalization of for and if are typos, you can't just
 add a slash / wherever you want to and expect perl to know
 why. Assuming that trailing slash is also a typo, And you
 really meant this ...

Apologies, Charles, I accidentally sent that off-list.  So, resend:

Maybe the capitalization of for and if wasn't a typo -- it might
have been the result of writing code in MS Word with auto-capitalization
turned on.

-- 
Chad Perrin [ CCD CopyWrite | http://ccd.apotheon.org ]
print substr(Just another Perl hacker, 0, -2);

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: has key/value pairs

2006-05-03 Thread Smith, Derek
-Original Message-
From: Charles K. Clarkson [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 03, 2006 5:41 PM
To: 'Perl Beginners'
Subject: RE: has key/value pairs

Smith, Derek wrote:

: Excellent... thank you. Before sending the email question, I
: was trying to use split to get rid of that and could not get
: it to work as I was using
: code
: 
: For (FH)
:   If (/pattern/) {
:split /\=/ ,$_ /;
:$vg{$_}++
:   }
: }
: /code
: 
: Why didn't this work?

Because it is wrong on so many levels. Seriously, assuming
the capitalization of for and if are typos, you can't just
add a slash / wherever you want to and expect perl to know
why. Assuming that trailing slash is also a typo, And you
really meant this ...

for (FH)
if (/pattern/) {
split /\=/, $_;
$vg{$_}++
}
}

... then there are still problems. First split() returns
a list of values, but you are not capturing that list. I think
that split() defaults to placing its values in @_, but you are
not accessing that here and it is deprecated.

All the work is being done in $vg{$_}++ which ignores
the split() and increments the value associated with the key
in $_. That one of those key/value pairs happens to be correct
is just coincidence.

*

Ok guys, yes that was just pseudo code and I was in a hurry to get it
off.
I was being lazy.  I have been around awhile, but laziness got the best
of me that time-around.
Now I understand why 

for (FH)
if (/pattern/) {
split /\=/, $_;
$vg{$_}++
}
}

will not work...aka I was not capturing that list.
Thank you
Derek


Derek Bellner Smith
Unix Systems Engineer
Cardinal Health Dublin, Ohio
614-757-5000 Main
614-757-8075 Direct
614-757-8120 Fax
[EMAIL PROTECTED]

Cardinal Health -- Working together. For life. (sm)
_

This message is for the designated recipient only and may contain privileged, 
proprietary, or otherwise private information. If you have received it in 
error, please notify the sender immediately and delete the original. Any other 
use of the email by you is prohibited.

Dansk - Deutsch - Espanol - Francais - Italiano - Japanese - Nederlands - Norsk 
- Portuguese - Svenska: www.cardinalhealth.com/legal/email

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response