Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: giving spaces

by Athanasius (Archbishop)
on Jul 17, 2013 at 04:49 UTC ( [id://1044709]=note: print w/replies, xml ) Need Help??


in reply to giving spaces

If the regex does not have an x modifier, just use a literal space. If it does have an x modifier, put the space into a character class:

13:26 >perl -wE "my $s = 'a b'; say 'matched' if $s =~ /a b/;" matched 14:47 >perl -wE "my $s = 'a b'; say 'matched' if $s =~ /a[ ]b/x;" matched 14:47 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: giving spaces
by Anonymous Monk on Jul 17, 2013 at 04:54 UTC
    say I have two arrays , arrayA and arrayB . and I wish to print something like this

    print " \s $arrayA[$i] \s $arrayB[$i] \s";

    I have assumed that \s is giving space , so I just want , what should i replace $s with ?

      If that's what you want to print, you don't need any space regex.

      print " $arrayA[$x] $arrayB[$x] ";

      will print the spaces too...

      I hope that helps.

      -Michael
      $var1." ".$var2;
      If you use use strict; use warnings; you will probably find an error in this statement that has nothing to do with spaces. I suspect that you intend $i to be a subscript. If so,
      print " $arrayA[$i] $arrayB[$i] ";
      Note: \s is special character class for regular expressions. It does not have the same meaning in a string. Just use space characters.
      Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1044709]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-19 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found