nursyza has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I wanted to print out the line below that was obtained from a text file without including the ";" at the end. How can I do that?

INPUT A, B, C, D;

#READ input A, B, C, D; my $INPUT_DATA = $_; if (defined($INPUT_DATA) && ($INPUT_DATA =~ /INPUT (.*)/)) { my $input_data = $1; my @input_array = split /,/, $1; my $size_input = @input_array; print "Input = "; print scalar "@input_array\n"; print "Number of input = $size_input\n"; }

Replies are listed 'Best First'.
Re: Pattern matching
by choroba (Cardinal) on Nov 13, 2018 at 10:49 UTC
    Don't include the semicolon to the capture group:
    $INPUT_DATA =~ /INPUT (.*);/)
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: Pattern matching
by Marshall (Canon) on Nov 13, 2018 at 19:16 UTC
    Another way:
    #!/usr/bin/perl use strict; use warnings; while (my $line = <DATA>) { next unless $line =~ /\S/; #skip blank lines my @array = $line =~ m/(\w+)/g; print "NUM ELEMENTS = ", scalar(@array), " @array\n"; } =prints NUM ELEMENTS = 4 A B C D NUM ELEMENTS = 5 X y Z BB AA NUM ELEMENTS = 3 C Somthing_else 5 =cut __DATA__ A, B, C, D; X,y, Z, BB AA; C, Somthing_else, 5
Re: Pattern matching
by Laurent_R (Canon) on Nov 13, 2018 at 19:04 UTC
    choroba's solution is perfect. You may also use the substitution operator:
    $input_data = s/;$//;
    or possibly the chop function if you are sure you want to trim the last character (but I would not really advise this latter solution).