×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Break array in parts at desired desired string.

Break array in parts at desired desired string.

Break array in parts at desired desired string.

(OP)
My array contains Huge log file, with each array element holding each line of the log.

Eg Log File:

I am Fresher line 1
I am Fresher line 2
I am Fresher line 3
.
.
.
I am Fresher line 64
I am Fresher line 65
Yo… I am not a fresher, starting my assignments line 66
Start of the first assignment line 67
Start of the Second assignment line 68
.
.
.
Start of the last assignment ine25880

My array contains 25880 elements starting from 0 to 25879.
I want split my array on line (Element) “Yo… I am not a fresher, starting my assignments line 66


So
new first array will be (of 65 elements in this example)
I am Fresher line 1
I am Fresher line 2
I am Fresher line 3
.
.
.
I am Fresher line 65
And
new Second array will be (of 25815 elements in this example)
Yo… I am not a fresher, starting my assignments line 66
Start of the first assignment line 67
Start of the Second assignment line 68
.
.
.
Start of the last assignment ine25880

RE: Break array in parts at desired desired string.

Like this

CODE

use strict;
use warnings;

my @array0 = qw/a b c You 1 2 3 4/;
my @array1 = ();
my @array2 = ();

# search for index
my $index = 0;
until ($array0[$index] =~ /Yo/) {
  $index++;
}
print "\$index = $index\n";

# split array into two
push @array1, @array0[0..($index-1)];
push @array2, @array0[$index..$#array0];

print "\$array0 = (@array0)\n";
print "\$array1 = (@array1)\n";
print "\$array2 = (@array2)\n"; 

Output

CODE

$index = 3
$array0 = (a b c You 1 2 3 4)
$array1 = (a b c)
$array2 = (You 1 2 3 4) 

RE: Break array in parts at desired desired string.

Little typo: It should be

CODE

print "\@array0 = (@array0)\n"; 
and so on ...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close