Home > Archive > PERL Beginners > May 2007 > Testing spliting value using if problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Testing spliting value using if problem
|
|
| moonhk 2007-05-22, 9:59 pm |
| Hi Reader
How to using if to test splited value ?
Use of uninitialized value in concatenation (.) at /home/ericl6/shell/
finger.pl line 43.
USER=28
Use of uninitialized value in print at /home/ericl6/shell/finger.pl
line 38.
USER=
Use of uninitialized value in scalar chomp at /home/ericl6/shell/
finger.pl line 39.
Use of uninitialized value in concatenation (.) at /home/ericl6/shell/
finger.pl line 43.
Use of uninitialized value in concatenation (.) at /home/ericl6/shell/
finger.pl line 43.
Use of uninitialized value in concatenation (.) at /home/ericl6/shell/
finger.pl line 43.
USER=28
USER=Feb
for (`cat /etc/passwd`)
{
($NAME,$D1,$D2,$D3,$USER,$HOME,$SHELL) = split/:/;
if ($HOME =~ m/home/) {
$CHKNAME = "";
#for (`finger $NAME |grep since | tail -1 |cut -c1-24`)
for (`last -1 $NAME`)
{
($D1,$D2,$D3,$USER,$HOME,$SHELL) = split ;
print "USER=",$USER, "\n";
if ( chomp($USER) eq "" ) {
$CHKNAME = "";
}
else {
$CHKNAME= $USER . " " . $HOME . " " . $SHELL;
$CNT1 = $CNT1 + 1;
}
}
$CNT0 = $CNT0 + 1;
# write();
}
}
| |
| Brad Baxter 2007-05-23, 6:59 pm |
| On May 22, 9:47 pm, moonhk <moon_ils...@yahoo.com.hk> wrote:
>
> How to using if to test splited value ?
if ( defined $USER ) { ...
> ($D1,$D2,$D3,$USER,$HOME,$SHELL) = split ;
....
> if ( chomp($USER) eq "" ) {
A. That's not the correct way to use chomp(), see perldoc -f chomp
B. $USER doesn't need to be chomped; it's not at the end of the line.
BTW: s/spliting/splitting/; s/splited/split/;
--
Brad
|
|
|
|
|