simple CGI question

hsosof

Junior Member
Aug 25, 2003
5
0
0
The chop command cuts off the last character in each array element, correct? So is there a command that will cut off the first character?
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
That's a perl question, not a CGI question. chop cuts off the last character of a string, it doesn't necesarily have to be in an array.
And unfortunately, there is no corresponding command for the first character of a string. Try this regular expression:

s/^.//;

So, instead of doing this:

chop $variable;

do this:

$variable =~ s/^.//;
 

hsosof

Junior Member
Aug 25, 2003
5
0
0
Worked like a charm, thanks! Do you mind explaining what it does? (I'm not exactly a Perl expert.)

And what is the difference between CGI and Perl, besides CGI being used as the front-end (I think)?
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Perl is a programming language, you can use it to write all kinds of different apps, including GUI apps for unix if you want to. CGI is an interface to webservers, it can use any language (I've written CGI programs in C, for example). All CGI is is a method of communication between a webserver and external programs (like your perl script).

Whatr that regex does:
the 's' denotes a substitution. Anything between the first two '/'s will be replaced with whatever is between the last two '/'s.
the '^' indicates the beginning of a string.
The '.' indicates any character.

so, you have /^./ Which indicates any character at the beginning of the string.
Then, you have // which is nothing.

so, you take the /^./ and replace it with //, and you replace any character at the beginning of the string with nothing.
 

hsosof

Junior Member
Aug 25, 2003
5
0
0
Thanks for the great information.

What does the ~ at the begginning of that line denote?
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: hsosof
Thanks for the great information.

What does the ~ at the begginning of that line denote?

I juts copied this directly from the perl documentation:

Binary "=~" binds a scalar expression to a pattern match. Certain operations search or modify the string $_ by default. This operator makes that kind of operation work on some other string. The right argument is a search pattern, substitution, or transliteration. The left argument is what is supposed to be searched, substituted, or transliterated instead of the default $_. When used in scalar context, the return value generally indicates the success of the operation. Behavior in list context depends on the particular operator. See /"Regexp Quote-Like Operators" for details.

If the right argument is an expression rather than a search pattern, substitution, or transliteration, it is interpreted as a search pattern at run time. This can be less efficient than an explicit search, because the pattern must be compiled every time the expression is evaluated.

Binary "!~" is just like "=~" except the return value is negated in the logical sense.