Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: With substr, index the offset don't get proper start position

by hippo (Bishop)
on Mar 21, 2019 at 10:55 UTC ( [id://1231529]=note: print w/replies, xml ) Need Help??


in reply to With substr, index the offset don't get proper start position

If you really want to do it using substr and index then here is one iterative method:

use strict; use warnings; my $line='PSAPPSRV.26476584 (6) 01/02/19 06:30:30 GetCertificate(3) Re +turning context. ID=PTWEBSERVER, Lang=ENG'; my $SpaceChar = ' '; my $result = $line; for (1..4) { $result = substr ($result, index ($result, $SpaceChar) + 1); print "$result\n"; }

Here's a simpler one with split instead:

#!/usr/bin/env perl use strict; use warnings; my $line='PSAPPSRV.26476584 (6) 01/02/19 06:30:30 GetCertificate(3) Re +turning context. ID=PTWEBSERVER, Lang=ENG'; my $SpaceChar = ' '; my $result = (split ($SpaceChar, $line, 5))[4]; print "$result\n";

Update: edit of first snippet to remove expensive no-op.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-20 02:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found