Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

giving spaces

by Anonymous Monk
on Jul 17, 2013 at 04:44 UTC ( #1044708=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:


what is the regex for space , \t is for tab . But can anyone help me me the symbol for space

Replies are listed 'Best First'.
Re: giving spaces
by Athanasius (Chancellor) on Jul 17, 2013 at 04:49 UTC

    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,

      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.

        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.
        $var1." ".$var2;
Re: giving spaces
by kcott (Chancellor) on Jul 17, 2013 at 05:23 UTC
Re: giving spaces
by Anonymous Monk on Jul 17, 2013 at 05:20 UTC
    hey anyone the escape sequence of space ?

      Under most circumstances, spaces don't need to be escaped. Just use a literal space.

      In the few cases where it does need to be escaped, the appropriate escape sequence depends on which case you're dealing with, so there's no single, universal answer. You'll need to specify the context in which you're escaping the space.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1044708]
Approved by kcott
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (1)
As of 2018-05-28 00:27 GMT
Find Nodes?
    Voting Booth?