need help extracting words from a string - Thanks and need more help

need help extracting words from a string - Thanks and need more help

Post by Jessi » Thu, 22 Aug 2002 03:46:43



This list Rocks! I have never gotten so much useful help from a list in my life. So many responces and so many ways of doing the same thing. Its amazing...

Thank you very much to everyone that responded with ideas to my problem. They have helped tremendously.

But now I have hopefully another one that is just as simple.

Is it possible to test if a hash variable is set? My thinking is something kinda like this:

if ( $hashname[variable] ) {
      do something smart again ;

Quote:}

Is that possible?

Thanks in advance,

Jessica

---------------------------------
Do You Yahoo!?
HotJobs, a Yahoo! service - Search Thousands of New Jobs

 
 
 

need help extracting words from a string - Thanks and need more help

Post by Shishir K. Sin » Thu, 22 Aug 2002 03:51:52


Quote:>Is it possible to test if a hash variable is set? My thinking is something kinda like this:
>if ( $hashname[variable] ) {
>      do something smart again ;
>}
>Is that possible?
>Thanks in advance,
>Jessica

You will be better off doing

if ( defined $hashname{'variable'} ) {
      do something smart again ;

Quote:}

and not

if ( $hashname{'variable'} ) {
      do something smart again ;

Quote:}

Since " if ( $hashname{'variable'} ) " will not be true for 0 and space

 
 
 

need help extracting words from a string - Thanks and need more help

Post by Mark Anders » Thu, 22 Aug 2002 03:55:21


I would point you to

perldoc -f exists
perldoc -f defined

and you will end up with either
if (exists $hashname{$variable})
if (defined $hashname{$variable})

depending on your definition of 'set'.

Notice the {} around the variable instead of [].

                /\/\ark

-----Original Message-----

Sent: Tuesday, August 20, 2002 11:47 AM

Subject: Re: need help extracting words from a string - Thanks and need

more help

This list Rocks! I have never gotten so much useful help from a list in my
life. So many responces and so many ways of doing the same thing. Its
amazing...

Thank you very much to everyone that responded with ideas to my problem.
They have helped tremendously.

But now I have hopefully another one that is just as simple.

Is it possible to test if a hash variable is set? My thinking is something
kinda like this:

if ( $hashname[variable] ) {
      do something smart again ;
}

Is that possible?

Thanks in advance,

Jessica

---------------------------------
Do You Yahoo!?
HotJobs, a Yahoo! service - Search Thousands of New Jobs

 
 
 

need help extracting words from a string - Thanks and need more help

Post by Connie Ch » Thu, 22 Aug 2002 19:25:50


Quote:> Is it possible to test if a hash variable is set? My thinking is something kinda like this:

> if ( $hashname[variable] ) {
>       do something smart again ;
> }

that's $hashname{variable}, not [variable]...

Yes, you can do that, but if you also turned on warnings,
you will receive a warning. To get rid of this warning :

&do_sth if (exists $hash{var});

or

&do_sth if (defined $hash{var});

Rgds,
Connie

 
 
 

1. need help extracting words from a string

I am such a knuckle head... I read the lists. I stumble through books and still I cant figure out how to do something that I would think should be relativly simple.

I am attempting to extract a two words or fields from every line of a tab delimited file. Sometimes the words that I need are in fields 1 & 2 and other time they are in 2 & 3. The lines look something like this:

TypeOfApp    ApplicationName     RunStatus
---------------------------------------------------------------------

application     run_me_now      complete                          <- Need 2 & 3
application2   ran_me_yesterday     complete/errors          <- Need 2 & 3
need_to_run_tomorrow     failed                                       <- Need 1 & 2

I am in need of just extracting the ApplicationName and RunStatus from the lines and placing them in variables so that I can do things with them.

I think I'm smart enought to know how to get the file opened and get the lines into a while loop like so:

open (FILE, ./datafile);

while (<FILE>) {
do something really smart here

But its just the "do something really smart here" thats got me baffled... (Grin)

Any help is greatly appreciated,

Jessica

---------------------------------
Do You Yahoo!?
HotJobs, a Yahoo! service - Search Thousands of New Jobs

2. resource pool?

3. need help : extract data from word to excel

4. Just a warning about a new virus...

5. ARRAY HELP NEEDED - My Partial Solution- More Help Needed

6. Oracle .dmp to mySQL

7. Cannot access IR-Port

8. Formula needed to extract the text from string

9. Need hard drive info HELP HELP HELP

10. **help**help**help**help**help**help**help

11. Thanks - Re: Regex problem extracting middle-word part of str ing

12. Regex problem extracting middle-word part of string