Walt Mankowski on 30 Jul 2007 22:52:19 -0000 |
And is there a reason you put the "use Switch" statement inside the loop? IMHO there's no good reason to use Switch.pm. Anything you'd want to do with Switch can be easily done with a bunch of nested if/else statements. Switch does its magic through the use of a fairly scary source filter, and I've heard reports (though I've never tried it myself) that you pay a performance penalty for using switch. There's also a reported bug that it messes up line numbers in the perl debugger. If you really love switch statements, I recommend you wait until perl 5.10 comes out (probably later on this year). 5.10 will have switch as an official part of the language, and so theoretically the two concerns I listed above should go away. Walt On Mon, Jul 30, 2007 at 05:42:32PM -0400, Mag Gam wrote: > Chris: > > Is there a reason why you chose switch() over if else {} ? > > > > On 7/30/07, W. Chris Shank <shankwc@acetechgroup.com> wrote: > > > > Thanks! > > > > > > ----- Original Message ----- > > From: Eric <eric@lucii.org> > > To: Philadelphia Linux User's Group Discussion List < > > plug@lists.phillylinux.org> > > Sent: Sunday, July 29, 2007 6:12:52 PM GMT-0500 > > Subject: Re: [PLUG] &!&@$%$%## Perl > > > > Chris: > > > > Putting "my" in front of "$displayName" inside the braces will > > restrict the scope of those variables to those enclosing braces. > > > > Remove the "my" from each case line and insert these as lines 2-4: > > > > my $displayName ; > > my $sn ; > > my $givenName ; > > > > > > > > Eric > > > > W. Chris Shank wrote: > > > I am trying to do a simple Case statement in perl. I have a file with > > > key:value pairs. I can parse out each key and the value via a loop, but > > > I only need 3 keys, so I'm trying to make a Case statement where if the > > > key equals any of 3 criteria the corresponding value is saved to a > > > variable. Here is my script so far - but the value is never written to > > > the variable. What am i doing wrong? Thanks perl wizards for your help. > > > > > > #!/usr/bin/perl > > > > > > while(<>) { > > > chomp; > > > my ($key,$value) = split(/:/); > > > > > > use Switch; > > > switch ($key) { > > > case "displayName" { my $displayName = $value } > > > case "sn" { my $sn = $value } > > > case "givenName" { my $givenName = $value } > > > else { } > > > } > > > > > > } > > > print "displayName $displayName \n"; > > > print "sn $sn \n"; > > > print "giveName $givenName \n"; > > > > > > > > > -- > > > W. Chris Shank > > > ACE Technology Group, LLC > > > www.myremoteITdept.com > > > (610) 640-4223 > > > > > > -------------------------------- > > > Security Note: To protect against computer viruses, > > > e-mail programs may prevent sending or receiving > > > certain types of file attachments. Check your e-mail > > > security settings to determine how attachments are > > > handled. > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > ___________________________________________________________________________ > > > Philadelphia Linux Users Group -- > > http://www.phillylinux.org > > > Announcements - > > http://lists.phillylinux.org/mailman/listinfo/plug-announce > > > General Discussion -- > > http://lists.phillylinux.org/mailman/listinfo/plug > > > > > > -- > > # Eric Lucas > > # > > # "Oh, I have slipped the surly bond of earth > > # And danced the skies on laughter-silvered wings... > > # -- John Gillespie Magee Jr > > > > ___________________________________________________________________________ > > Philadelphia Linux Users Group -- > > http://www.phillylinux.org > > Announcements - > > http://lists.phillylinux.org/mailman/listinfo/plug-announce > > General Discussion -- > > http://lists.phillylinux.org/mailman/listinfo/plug > > > > > > -- > > W. Chris Shank > > ACE Technology Group, LLC > > www.myremoteITdept.com > > (610) 640-4223 > > > > -------------------------------- > > Security Note: To protect against computer viruses, > > e-mail programs may prevent sending or receiving > > certain types of file attachments. Check your e-mail > > security settings to determine how attachments are > > handled. > > > > > > ___________________________________________________________________________ > > Philadelphia Linux Users Group -- > > http://www.phillylinux.org > > Announcements - > > http://lists.phillylinux.org/mailman/listinfo/plug-announce > > General Discussion -- > > http://lists.phillylinux.org/mailman/listinfo/plug > > > > > ___________________________________________________________________________ > Philadelphia Linux Users Group -- http://www.phillylinux.org > Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce > General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug Attachment:
signature.asc ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|
|