Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

[perl]looking for specific text in a variable

Name: Sol 2007-01-18 16:17

How do I look for specific text in a variable?
Continuing from log parsing discussion.

Last question, then I shuddap.

Name: Anonymous 2007-01-18 16:22

if ($variable =~ /specific text/) {
    # are you too fucking lazy to read some books on Perl?
}

Name: Anonymous 2007-01-18 16:25

Given that its perl you are working with, I'm pretty sure you'll want to use regular expressions. Something like /s/text or something. Also I suck at regexp, and I hate it because it looks different wherever its implemented.

Name: Anonymous 2007-01-18 16:26

Name: Anonymous 2007-01-18 16:27

>>1
>>2
>>3
>>4
Wow. /prog/ is fast today. What happened?

Name: Sol 2007-01-18 16:36

>>2
Yup. Not too lazy to google for it, though, and the method I ended up using was pretty much exactly like this. Stupid here decides to google something after posting here instead of before.

GO ME.

Name: Anonymous 2007-01-18 17:32

>Sol:
>>2 LISTEN TO THIS MAN

Read Perl Programming by Larry Wall and go away. They should have it at your library in the Computers section.

Name: Sol 2007-01-18 18:11

>>7
Too far away from a library, no means to get to one, and I'm out of college. Ain't happening, I'm afraid.

Name: Anonymous 2007-01-19 3:05

>>8
It's downloadable on the interwebs

Name: Anonymous 2007-01-19 5:06

>>5
We all got fired?

Name: Regex !PaNICaHDGU 2007-01-21 3:50

Your instructions suck, here's how you do it:

Searching literal strings in other string, somewhat equivalent to C strstr or strcasestr:

if($text = /\Q$search/) ...

OR

if($text = /\Q$search/i) ... # for case insensitive

OR

if(index($text,$search) != -1) ...

Name: Sgt.Kabuꎳ⭗kiman䑢䟧 2012-05-28 21:54

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List