in reply to concatenating strings

To concatenate, do this

$concatfile = "$t$i";
or this
$concatfile = $t . $i;
...though in this case you might as well do the whole thing in one swoop, and check return status while you're at it:
system( "$t$i.bat" ) == 0 or die "system( $t$i.bat ) failed: $?";
You may need to use $^E instead of $? for that error check (though I'm not familiar enough with Win32 programming to know for sure).

the lowliest monk

Replies are listed 'Best First'.
Re^2: concatenating strings
by imperl (Novice) on May 04, 2005 at 11:31 UTC
    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

      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!:)
      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.

      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.:)