Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: how to ignore spaces, commas or new line of an array when comparing

by hippo (Bishop)
on Jun 16, 2021 at 08:33 UTC ( #11133911=note: print w/replies, xml ) Need Help??


in reply to how to ignore spaces, commas or new line of an array when comparing

That almost sounds like the use case for the WhiteSpace option. Did you try that?

If you still have problems, I recommend that you show precisely how your arrays are created. eg:

my @array1 = ('abc ', 'xyz');

... and so on. This removes any ambiguity about the data you actually have.


🦛

  • Comment on Re: how to ignore spaces, commas or new line of an array when comparing
  • Download Code

Replies are listed 'Best First'.
Re^2: how to ignore spaces, commad or new line of an array when comparing
by noviceuser (Novice) on Jun 16, 2021 at 08:44 UTC

    in @array1, the contents are being pushed and in @array2, the contents are being read from a file and stored in the @array2

      How does that reply address "show precisely how your arrays are created" (see I know what I mean. Why don't you?)? Perhaps you intended to write something like:

      use strict; use warnings; my $fStr = <<FSTR; abc xyz FSTR open my $inFile, '<', \$fStr; my @array2 = <$inFile>; my @array1 = ('abc ', 'xyz');
      Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

      Hmmm. Is your real question then "How do I clean whitespace from data read from a file?" or something like that? Or do you really want one array with whitespace and one without?


      🦛

        yes..i want to clean whitespaces/new line or any speacial character from array2 and make it comparable to array1

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2021-10-20 11:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (81 votes). Check out past polls.

    Notices?