in reply to Re: concatenating strings
in thread concatenating strings

I did that, but I get an error, "unknown file". However, if I specify the value of $t = xyz and then $concatfile = $t.$i, it works perfectly. The moment I enter the value of $t, it gives an error. Is there some kind of format to concat 2 strings, one of which is a variable entered during file execution, <STDIN>?

Tried the ^ too, is this what you mean?

print "Enter the common character in the batch file:\n"; $t=<STDIN>; print "Enter the number in the first batch file:\n"; $f=<STDIN>; print "Enter the number in the last batch file:\n"; $l=<STDIN>; for ($i=$f;$i<=$l; $i++) { #$t="file"; #$concatfile=$t.$i; #$file="$concatfile.bat"; system( "$^t$i.bat" ); #system($file); sleep(2); }

Janitored by Arunbear - added code tags, as per Monastery guidelines

Replies are listed 'Best First'.
Re^3: concatenating strings
by Joost (Canon) on May 04, 2005 at 11:39 UTC
    tlm's code is correct, so if there's anything not working, I suspect you're not removing the newline from the filename (a line from a filehandle will always end in newline unless EOF happens first)

    you should do something like:

    print "Enter basename: "; my $filename = <STDIN>; chomp $filename;

    You can check that the variables actually contain what you think they do by printing them out with delimiters around them:

    print "File=>>$filename<<\n";
      Thank You, Joost and tlm. What can I say, the ubiquitous chomp did it!:)
Re^3: concatenating strings
by polettix (Vicar) on May 04, 2005 at 11:53 UTC
    imperl, I suspect you did not read this, which suggests you to print out the filename you're building: print is your friend in debugging! Moreover, use strict and use warnings should never miss when building example codes to post here: they will answer many questions much more quickly than us! As a final note, you should use <code> tags when posting :)

    I think that you have problems with the newline: when you read from STDIN, it will be put inside $f. Just chomp inputs:

    print "Enter the common character in the batch file:\n"; chomp(my $f = <STDIN>); print "Enter the number in the last batch file:\n"; chomp(my $l=<STDIN>); # Now both $f and $l have no trailing newline

    Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

    Don't fool yourself.
Re^3: concatenating strings
by tlm (Prior) on May 04, 2005 at 11:42 UTC

    You probably need to chomp the line-termination sequence off that user input. Try

    $t = <STDIN>; chomp $t; # removes trailing line-termination sequence # ... system( "$t$i.bat" ) == 0 or die "system( $t$i.bat ) failed: $^E";

    the lowliest monk

      Thanks , chomp worked.:)