Skip to content

split continues past end of string #5179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
p5pRT opened this issue Mar 1, 2002 · 6 comments
Closed

split continues past end of string #5179

p5pRT opened this issue Mar 1, 2002 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 1, 2002

Migrated from rt.perl.org#8740 (status was 'resolved')

Searchable as RT8740$

@p5pRT
Copy link
Author

p5pRT commented Mar 1, 2002

From [email protected]

#!/bin/perl -w

$_ = " trash.prl -d -c f_trash.fponly.cmd -o f_trash.fponly
" ;
/trash\.prl/ ;
$cmdstr = $' ;
$cmdstr =~ s/-o [\w.]+// ;
@​cmdline = split , $cmdstr ;

print $_ ;
print $cmdstr ;
print join " ", @​cmdline , "\n" ;

prints the following​:
  trash.prl -d -c f_trash.fponly.cmd -o f_trash.fponly
-d -c f_trash.fponly.cmd
trash.prl -d -c f_trash.fponly.cmd -o f_trash.fponly

perl -V​:
Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration​:
  Platform​:
  osname=aix, osvers=4.3.3.0, archname=aix
  uname='aix gmp049 3 4 000106349400 '
  config_args=''
  hint=previous, useposix=true, d_sigaction=define
  usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
  useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
  use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler​:
  cc='cc', ccflags ='-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE
-qmaxmem=16384 -DDEBUGGING -q32 -D_LARGE_FILES -qlonglong',
  optimize='-g',
  cppflags='-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=16384
-DDEBUGGING -q32 -D_LARGE_FILES -qlonglong'
  ccversion='5.0.1.0', gccversion='', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
  alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries​:
  ld='ld', ldflags =' -b32'
  libpth=/lib /usr/lib /usr/ccs/lib
  libs=-lbind -lnsl -ldbm -ldl -lld -lm -lC -lc -lcrypt -lbsd -lPW
-liconv
  perllibs=-lbind -lnsl -ldl -lld -lm -lC -lc -lcrypt -lbsd -lPW -liconv
  libc=, so=a, useshrplib=false, libperl=libperl.a
  Dynamic Linking​:
  dlsrc=dl_aix.xs, dlext=so, d_dlsymun=undef, ccdlflags='
-bE​:ROOTDIR/perl5/lib/5.6.1/aix/CORE/perl.exp
-bE​:ROOTDIR/perl5/lib/5.6.1/aix/CORE/perl.exp'
  cccdlflags=' ', lddlflags='-bhalt​:4 -bM​:SRE -bI​:$(PERL_INC)/perl.exp
-bE​:$(BASEEXT).exp -b noentry -lC -lc'

Characteristics of this binary (from libperl)​:
  Compile-time options​: DEBUGGING USE_LARGE_FILES
  Built under aix
  Compiled at Aug 14 2001 14​:03​:57
  @​INC​:
  ROOTDIR/perl5/lib/5.6.1/aix
  ROOTDIR/perl5/lib/5.6.1
  ROOTDIR/perl5/lib/site_perl/5.6.1/aix
  ROOTDIR/perl5/lib/site_perl/5.6.1
  ROOTDIR/perl5/lib/site_perl
  .

I have NOT attempted to narrow the problem past these eight lines. I hope
that's okay...

JAPHW

Nathan Zook

__________________________________________________
That [state] which separates its scholars from its warriors will have its
thinking done by cowards, and its fighting done by fools.
-- Thucydides, "The Peloponneaisn Wars"

@p5pRT
Copy link
Author

p5pRT commented Mar 1, 2002

From @tamias

On Fri, Mar 01, 2002 at 04​:42​:20PM -0600, Nathan H Zook wrote​:

This is a bug in your script, rather than in perl.

#!/bin/perl -w

$_ = " trash.prl -d -c f_trash.fponly.cmd -o f_trash.fponly
" ;
/trash\.prl/ ;
$cmdstr = $' ;
$cmdstr =~ s/-o [\w.]+// ;
@​cmdline = split , $cmdstr ;

This line is parsed as​:

(@​cmdline = split), $cmdstr;

which is equivalent to​:

(@​cmdline = split " ", $_), $cmdstr;

Presumably, you meant something like​:

@​cmdline = split " ", $cmdstr;

Ronald

@p5pRT
Copy link
Author

p5pRT commented Mar 1, 2002

From [Unknown Contact. See original ticket]

On Mar 1, Nathan H Zook said​:

$_ = " trash.prl -d -c f_trash.fponly.cmd -o f_trash.fponly
" ;
/trash\.prl/ ;
$cmdstr = $' ;
$cmdstr =~ s/-o [\w.]+// ;
@​cmdline = split , $cmdstr ;

Perl has parsed that as

  (@​cmdline = split), $cmdstr;

so you end up splitting $_ on whitespace​:

  (@​cmdline = split ' ', $_), $cmdstr;

Here's the Deparse output​:

  pinyaj@​vcmr-86 [5​:58pm] ~ #106> perl -MO=Deparse,-p -e '@​a = split, $b'
  -e syntax OK
  ((@​a = split(/\s+/, $_, 0)), $b);

If you had the -w switch on, you'd have been told $cmdstr was being used
in void context.

  @​cmdline = split ' ', $cmdstr;

seems appropriate.

--
Jeff "japhy" Pinyan japhy@​pobox.com http​://www.pobox.com/~japhy/
RPI Acacia brother #734 http​://www.perlmonks.org/ http​://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]

@p5pRT
Copy link
Author

p5pRT commented Mar 1, 2002

From @mjdominus

It appears that the bug is in your program, not in Perl.

#!/bin/perl -w

$_ = " trash.prl -d -c f_trash.fponly.cmd -o f_trash.fponly
" ;
/trash\.prl/ ;
$cmdstr = $' ;
$cmdstr =~ s/-o [\w.]+// ;
@​cmdline = split , $cmdstr ;

This line is equivalent to​:

  (@​cmdline = split), $cmdstr;

which is why you got the "useless use of variable" warning. Since you
didn't give any arguments to 'split', it is splitting $_, which
contains

  trash.prl -d -c f_trash.fponly.cmd -o f_trash.fponly

so that @​cmdline gets​:

  ('trash.prl', '-d', '-c', 'f_trash.fponly.cmd',
  '-o','f_trash.fponly')

If you want to split $cmdstr itself, you must use something like

  split ' ', $cmdstr;

I hope this helps you with your problem.

I have NOT attempted to narrow the problem past these eight lines. I hope
that's okay...

Fine, but​:

1) next time, please say what output you expected to get, in addition
to what output you did get, and

2) next time, please don't change anything below the line that says
"[Please do not change anything below this line]".

Thanks for submitting your report.

@p5pRT
Copy link
Author

p5pRT commented Mar 1, 2002

From [Unknown Contact. See original ticket]

#!/bin/perl -w

$_ = " trash.prl -d -c f_trash.fponly.cmd -o f_trash.fponly
" ;
/trash\.prl/ ;
$cmdstr = $' ;
$cmdstr =~ s/-o [\w.]+// ;
@​cmdline = split , $cmdstr ;

print $_ ;
print $cmdstr ;
print join " ", @​cmdline , "\n" ;

prints the following​:
  trash.prl -d -c f_trash.fponly.cmd -o f_trash.fponly
-d -c f_trash.fponly.cmd
trash.prl -d -c f_trash.fponly.cmd -o f_trash.fponly

perl -V​:
Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration​:
  Platform​:
  osname=aix, osvers=4.3.3.0, archname=aix
  uname='aix gmp049 3 4 000106349400 '
  config_args=''
  hint=previous, useposix=true, d_sigaction=define
  usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
  useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
  use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler​:
  cc='cc', ccflags ='-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE
-qmaxmem=16384 -DDEBUGGING -q32 -D_LARGE_FILES -qlonglong',
  optimize='-g',
  cppflags='-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=16384
-DDEBUGGING -q32 -D_LARGE_FILES -qlonglong'
  ccversion='5.0.1.0', gccversion='', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
  alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries​:
  ld='ld', ldflags =' -b32'
  libpth=/lib /usr/lib /usr/ccs/lib
  libs=-lbind -lnsl -ldbm -ldl -lld -lm -lC -lc -lcrypt -lbsd -lPW
-liconv
  perllibs=-lbind -lnsl -ldl -lld -lm -lC -lc -lcrypt -lbsd -lPW -liconv
  libc=, so=a, useshrplib=false, libperl=libperl.a
  Dynamic Linking​:
  dlsrc=dl_aix.xs, dlext=so, d_dlsymun=undef, ccdlflags='
-bE​:ROOTDIR/perl5/lib/5.6.1/aix/CORE/perl.exp
-bE​:ROOTDIR/perl5/lib/5.6.1/aix/CORE/perl.exp'
  cccdlflags=' ', lddlflags='-bhalt​:4 -bM​:SRE -bI​:$(PERL_INC)/perl.exp
-bE​:$(BASEEXT).exp -b noentry -lC -lc'

Characteristics of this binary (from libperl)​:
  Compile-time options​: DEBUGGING USE_LARGE_FILES
  Built under aix
  Compiled at Aug 14 2001 14​:03​:57
  @​INC​:
  ROOTDIR/perl5/lib/5.6.1/aix
  ROOTDIR/perl5/lib/5.6.1
  ROOTDIR/perl5/lib/site_perl/5.6.1/aix
  ROOTDIR/perl5/lib/site_perl/5.6.1
  ROOTDIR/perl5/lib/site_perl
  .

I have NOT attempted to narrow the problem past these eight lines. I hope
that's okay...

JAPHW

Nathan Zook

__________________________________________________
That [state] which separates its scholars from its warriors will have its
thinking done by cowards, and its fighting done by fools.
-- Thucydides, "The Peloponneaisn Wars"

@p5pRT
Copy link
Author

p5pRT commented Mar 4, 2002

From [Unknown Contact. See original ticket]

Doh! Thank-you gentlemen. The worst part is that I had -w on, and didn't
figure out what it was telling me.

JAPHW,

Nathan

The W, of course, having now been properly confirmed.

__________________________________________________
That [state] which separates its scholars from its warriors will have its
thinking done by cowards, and its fighting done by fools.
-- Thucydides, "The Peloponneaisn Wars"

 
  Ronald J Kimball
  <rjk@​linguist.thayer.dar To​: Nathan H Zook/Austin/IBM@​IBMUS
  tmouth.edu> cc​: perl5-porters@​perl.org
  Subject​: Re​: [ID 20020301.013] split continues past end of string
  03/01/02 04​:58 PM
 
 

On Fri, Mar 01, 2002 at 04​:42​:20PM -0600, Nathan H Zook wrote​:

This is a bug in your script, rather than in perl.

#!/bin/perl -w

$_ = " trash.prl -d -c f_trash.fponly.cmd -o f_trash.fponly
" ;
/trash\.prl/ ;
$cmdstr = $' ;
$cmdstr =~ s/-o [\w.]+// ;
@​cmdline = split , $cmdstr ;

This line is parsed as​:

(@​cmdline = split), $cmdstr;

which is equivalent to​:

(@​cmdline = split " ", $_), $cmdstr;

Presumably, you meant something like​:

@​cmdline = split " ", $cmdstr;

Ronald

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant