• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

/ operator

What does / do in PERL?

Where can I find more info on / online?

Thanks!
0
Tom Knowlton
Asked:
Tom Knowlton
  • 9
  • 3
  • 2
  • +3
1 Solution
 
Tom KnowltonWeb developerAuthor Commented:
For example:

/^

/e

/ee

/\

etc.

etc.
0
 
ahoffmannCommented:
man perlop
man perlre
0
 
Tom KnowltonWeb developerAuthor Commented:
...huh???
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
bebonhamCommented:
or for the unix impared,

http://www.perldoc.com/perl5.6/pod/perlop.html

I think they typically use / for division.
0
 
Tom KnowltonWeb developerAuthor Commented:
/ is not used for division in the contect I am thinking of, I don't think...

Yes, I am unix-impaired  :)
0
 
holliCommented:
could you please provide some code snippets. just to let us see the context.
the char / can have many meanings.

(quote char, regexp separator, special var ($/) ...)

0
 
Tom KnowltonWeb developerAuthor Commented:
I think regex separator and special var is where I am headed with this.

I will find some code snippets, but I'm out of time today...I'll paste them in tomorrow...
0
 
red5Commented:
a couple simple regex examples:

here we see if the variable (called scalar in perl) $variable contains "THIS TEXT"

if ( $var =~ /THIS TEXT/ ) {
  # yes it does
}

say you didn't know how many spaces were between THIS and TEXT.  you could:

if ( $var =~ /THIS\s+TEXT/ ) {
  # yes it does
}

\s means any whitespace character (space, tab, carriage return).  \s+ means 1 or more whitespace characters, so that would match:

THIS TEXT
THIS  TEXT
THIS <tab> TEXT

does this help?
0
 
ahoffmannCommented:
what was wrong with my suggestion?
It prints out online (on UNIX) what you want.
If you mean that "online" is always connected to the internet then use:
   http://www.perldoc.com/perl5.6/pod/perlop.html
   http://www.perldoc.com/perl5.6/pod/perlre.html
or even
   http://www.perldoc.com/perl5.6/pod/
as bebonham suggested
0
 
Tom KnowltonWeb developerAuthor Commented:
ahoffmann:

I never said there was anything wrong with your suggestion.  I am still deciding which answer I like best.

red5 has given what look like some pretty good examples.

I need to go check your links, ahoofmann, and evaluate if they provide the answer I need.

Thanks,

Tom
0
 
Tom KnowltonWeb developerAuthor Commented:
I am strictly Win32, btw.

Unix specific examples won't work properly.
0
 
maneshrCommented:
knowlton,

"...What does / do in PERL?

Where can I find more info on / online?..."

Can you please provide more detail on the context in which you are using /  ?
E.g. any code snippet that has the / about which you need more info etc..

That will help you get a more accurate answer, faster.

Let me know.
0
 
Tom KnowltonWeb developerAuthor Commented:
Okay:

@names=('Mrs Smith','Mr Jones','Ms Samuel','Dr Jansen','Sir Philip');

foreach $person (@names) {
     print "$person\n";
     last if $person=~/Dr /;


THe /Dr  /; part....what is the / doing?

What is /   in Perl?
0
 
Tom KnowltonWeb developerAuthor Commented:
OR this:

$_='HTML <I>munging</I> time !.';

/<I>(.*)<\/I>/i;

print "Found it ! $1\n";
0
 
bebonhamCommented:
in those two cases, they are only used as delimiters for regular expressions.

the '/' before the I in both examples is literal.
in the regexp, it is escaped because '/' is also used as the delimiter.
0
 
maneshrCommented:
knowlton,

"...THe /Dr  /; part....what is the / doing?..."

In this case the / is used as a quote characters with the  pattern matching operator m

 last if $person=~/Dr /;

In simple terms the above line of code says if the variable $person contains the string Dr followed by a space character, exit out of the for loop.

you can also write the above statement as...

 last if $person=~ m/Dr /;

## NOTE:  the m may be omitted if the delimiters you pick are in fact slashes

Alternately, you can use ANY quote character.

E.g.

 last if $person=~ m'Dr ';
## NOTE: i have used ' instead of /


Again this is the same case in the 2nd example, wher you are searching the $_ special variable for
the string mentioned inside / /

NOTE: since you have added i at the end, the pattern match is case insensitive.
So the <I> can be <i> or <I> etc...

Hope that clarifies things.
0
 
Tom KnowltonWeb developerAuthor Commented:
Thank you, everyone.
0
 
maneshrCommented:
knowlton,

You're welcome.

Glad to know you got the solution you were looking for.
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 9
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now