Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 890013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:39:33+00:00 2026-05-15T13:39:33+00:00

Data Format: attribname: data Data Example: cheese: good pizza: good bagel: good fire: bad

  • 0

Data Format:

attribname: data

Data Example:

cheese: good
pizza: good
bagel: good
fire: bad

Code:

my $subFilter='(.+?): (.+)';
my @attrib = ($dataSet=~/$subFilter/g);
for (@attrib)
{
   print "$_\n";
}

The code spits out:

cheese
good
pizza
good
[etc...]

I was wondering what an easy Perly way to do this is? I am parsing the data from a log the data above is trash for simplicity. I am newer to Perl, I suspect I could do this via fanangling indexes, but I was wondering if there is a short method of implementing this? Is there any way to have the capture groups put into two different variables instead of serially appended to the list along with all matches?

Edit: I want the attribute and it’s associated value together so I can the do what I need to to them. For example if within my for loop I could access both the attribute name and attribute value.

Edit:

I tried

my %attribs;
while (my $line = <$data>)
{
     my ($attrib, $value) = ($line=~m/$subFilter/);
     print $attribs{$attrib}," : ", $value,"\n";
}

and no luck 🙁 I don’t get any output with this. My data is in a variable not a file, because it parsed out of a set of parent data which is in a file. It would be convenient if the my variable worked so that my (@attrib, @value) = ($line=~/$subFilter/g); filled the lists appropriately with the multiple matches.

Solution:

my @line = ($7 =~/(.+?)\n/g);
for (@line)
{
  my ($attrib, $value) = ($_=~m/$subFilter/);
  if ($attrib ne "")
  {
     print $attrib," : ", $value,"\n";
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:39:33+00:00Added an answer on May 15, 2026 at 1:39 pm

    I’m not really clear on what you actually want to store, but here’s how you could store the data in a hash table, with ‘1’ indicating good and ‘0’ indicating ‘bad’:

    use strict;
    use warnings;
    
    use Data::Dumper;
    
    my %foods;
    while (my $line = <DATA>)
    {
        chomp $line;
        my ($food, $good) = ($line =~ m/^(.+?): (.+)$/);
        $foods{$food} = ($good eq 'good' ? 1 : 0);
    }
    
    print Dumper(\%foods);
    
    __DATA__
    cheese: good
    pizza: good
    bagel: good
    fire: bad
    

    This prints:

    $VAR1 = { 
              'bagel' => 1,
              'cheese' => 1,
              'fire' => 0,
              'pizza' => 1
            };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to print out the data, for debugging purpose. Data format would
i have one date. example : $date='2011-21-12' ; data format :yyyy-dd-mm; IF date is
Please help in writing a code for conversion of source data in dd/mm/yyyy format.
I have data format below int : int \t string for example, 11:11 long
The data format I got back from URL is in this format: #RES#[{status:Stopped \/
I'm developping a xml data format. Besides other data there should be a xaml
I would like to create my own data format for an iPhone app. The
Error translated from Portuguese to English: Error data conversion or data format conversion. I
I have a XML file with the following data format: <net NetName=abc attr1=123 attr2=234
I'm working on a Google AppEngine project and I've changed my data format, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.