Gossamer Forum
Home : General : Perl Programming :

Purpose of pound signs ( # ) in defining scalar

Quote Reply
Purpose of pound signs ( # ) in defining scalar
Hi All

Can someone please tell me what the purpose of the # signs in the following is? I've been hunting around, but I can't find it. I'm trying to modify a form script to include a date as part of the logfile.txt name - /log_date.txt - to gather visitor info:

my $file = shift @_;
$file =~ s#\.\./##g;

Thank you very much Smile

DT

Quote Reply
Re: [DogTags] Purpose of pound signs ( # ) in defining scalar In reply to
They're just using # as a replacement for the 'standard' forward slash (/) in a regex. In that example they use something other than / so that they don't have to escape the /'s.
You can use lots of different ones for it.. like
s|foo|bar|
s(foo)(bar)
s,foo,bar,
...


Adrian

Last edited by:

brewt: Oct 5, 2001, 1:07 AM
Quote Reply
Re: [brewt] Purpose of pound signs ( # ) in defining scalar In reply to
Thanks, Adrian. I just found it in a side note this morning.

I appreciate your help Smile

DT
Quote Reply
Re: [DogTags] Purpose of pound signs ( # ) in defining scalar In reply to
Note that you can only do that with substitution and m//, something like this won't work:

$var =~ #\d+#ig;


Quote Reply
Re: [RedRum] Purpose of pound signs ( # ) in defining scalar In reply to
10-4, RedRum. Good point Smile

DT

Last edited by:

DogTags: Oct 5, 2001, 7:13 AM