Logo
  • Home
  • About
  • Services
  • Blogs
  • Career
  • Contact
Logo

The UK's #1 Software Development Company. PodTech IO builds custom software solutions for businesses. Call today for a free consultation

  • Address

    4th Floor, 4 Tabernacle Street London EC2A 4LU
  • Email

    info@podtech.com
  • Contact

    +44 (0) 20 8720 6583

Perl Split

  • Home
  • Perl Split
  • By podtech
  • In Perl

Perl Split

A very useful function in Perl is split, which splits up a string and places it into an array. The function uses a regular expression and as usual works on the $_ variable unless otherwise specified.

The split function is used like this:

[perl]
$info = “Caine:Michael:Actor:14, Leafy Drive”;
@personal = split(/:/, $info);
[/perl]

which has the same overall effect as

[perl]
@personal = ("Caine", "Michael", "Actor", "14, Leafy Drive");
[/perl]

If we have the information stored in the $_ variable then we can just use this instead

[perl]
@personal = split(/:/);
[/perl]

If the fields are divided by any number of colons then we can use the RE codes to get round this. The code

[perl]
$_ = “Capes:Geoff::Shot putter:::Big Avenue”;
@personal = split(/:+/);
[/perl]

is the same as

[perl]
@personal = (“Capes”, “Geoff”, “Shot putter”, “Big Avenue”);
[/perl]

But this:

[perl]
$_ = “Capes:Geoff::Shot putter:::Big Avenue”;
@personal = split(/:/);
[/perl]

would be like

[perl]
@personal = (“Capes”, “Geoff”, “”, “Shot putter”, “”, “”, “Big Avenue”);
[/perl]

A word can be split into characters, a sentence split into words and a paragraph split into sentences:

[perl]
@chars = split(//, $word);
@words = split(/ /, $sentence);
@sentences = split(/\./, $paragraph);
[/perl]

In the first case the null string is matched between each character, and that is why the @chars array is an array of characters – ie an array of strings of length 1.

PerlPerl Splitsplit function
Blackberry Orange – APN Settings
Solaris 10 – Create an NFS Share

Recent Posts

  • DevOps as a Software Development Methodology
  • How Does Spiral Software Development Methodology Work?
  • Waterfall Software Development Methodology And When To Use It
  • What Exactly Is Lean Software Development Methodology?
  • What is Kanban and How Does It Work?

PodTech IO

The UK's #1 Software Development Company. PodTech IO builds custom software solutions for businesses. Call today for a free consultation

Company

  • About
  • Services
  • Contact
  • Blogs
  • Career

Terms

  • Terms & Conditions
  • Privacy Policy

Contact Us

  • ADDRESS

    Headquarter: Tabernacle Street London India: Vi john Tower, Gurgaon, Haryana
  • EMAIL

    info@podtech.com
  • CONTACT

    +44 (0) 20 8720 6583

Copyright ©2023 PodTech IO. All Rights Reserved

Logo