Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Load list into array from text file with PERL

Posted on 2010-08-13
2
483 Views
Last Modified: 2012-05-10
Hi

I started playing around with perl and need some input on this. If I have a file with usernames in this format:

username1, username2, username3, username4, etc.

how do i load this into an array and how do I then append a new name to the end of the file.

0
Comment
Question by:QuintusSmit
2 Comments
 
LVL 10

Accepted Solution

by:
jeromee earned 125 total points
ID: 33429820
use strict;
my $file = "/file/path/here";

# Read names from file
open(FILE, $file) || die "Can't open $file: $!";
my $listOfNames = <FILE>;
close(FILE);
chomp $listOfNames;
my @names = split /[, ]+/, $listOfNames;

push(@names, "userM", "userN");  # Add new names like this...


# write names to file
open(FILE, ">$file") || die "Can't open $file: $!";
print FILE join(",", @names);
close(FILE);
0
 
LVL 1

Author Closing Comment

by:QuintusSmit
ID: 33430079
thank you - i'll have some more questions soon
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question