![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| searching and storing unknown number of lines based on the string with a condition | swamymns | Shell Programming and Scripting | 7 | 05-12-2008 10:02 PM |
| extract same word from two files | tjmannonline | AIX | 4 | 04-06-2008 09:42 AM |
| extract numbers from a word | systemali | Shell Programming and Scripting | 6 | 03-20-2006 06:09 AM |
| extract last word on line to new file | michieka | UNIX for Dummies Questions & Answers | 10 | 05-07-2002 08:26 AM |
| Selecting unknown string. | Cameron | UNIX for Dummies Questions & Answers | 2 | 12-18-2001 11:48 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
perl newbie: how to extract an unknown word from a string
hi,
im quite new to perl regexp. i have a problem where i want to extract a word from a given string. but the word is unknown, only fact is that it appears as the second word in the string. Eg. input string(s) : char var1 = 'A'; int var2 = 10; char *ptr; and what i want to do is to get the variable name (var1, var2, ptr ..etc.) from an above like string. can we use something like (w+) to match a whole word. thankx in advance. wolwy. |
| Forum Sponsor | ||
|
|
|
|||
|
An easier way might be to use the split function. The following example shows you how to use the split function to extract words from a string.
Code:
#!/usr/local/bin/perl -w
my $str = "The quick brown box";
my @words = split(' ', $str);
foreach my $word (@words) {
print "$word\n";
}
print "All words: @words\n";
print "Second word: @words[1]\n";
exit 0;
|
| Thread Tools | |
| Display Modes | |
|
|