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 4545926
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:52:54+00:00 2026-05-21T15:52:54+00:00

I have a hash %h which I would like to save as YAML. #!/usr/bin/perl

  • 0

I have a hash %h which I would like to save as YAML.

#!/usr/bin/perl

use warnings;
use strict;

my %h = ();

# -----

use YAML::Syck;
my $y = YAML::Syck::LoadFile('have_seen.yaml');

$y->%h ???

my $yaml = YAML::Syck::Dump($y);
$yaml::Syck::ImplicitUnicode = 1;

open F, ">have_seen.yaml" or die $!;
print F $yaml . "---\n";
close F;

But it seams like a chicken and egg problem.

How do I write the yaml file for the first time, so it can be read?

Update: Based on the accepted answer was the solution

#!/usr/bin/perl

use warnings;
use strict;
use YAML::Syck;
use Data::Dumper;

my $first_time = 1;

if ($first_time) {

    my %h = ("1" => 2);

    open F, '>', 'seen.yaml';
    print F YAML::Syck::Dump(\%h);
    close F;

} else {

    my $h = YAML::Syck::LoadFile('seen.yaml');

    $h->{"3"} = 4;

    print Dumper $h;

    my $yaml = YAML::Syck::Dump($h);
    $yaml::Syck::ImplicitUnicode = 1;

    open F, ">seen.yaml" or die $!;
    print F $yaml . "---\n";
    close F;
}
  • 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-21T15:52:55+00:00Added an answer on May 21, 2026 at 3:52 pm

    Use Dump to convert an arbitrary object to a YAML-encoded string, then print that string to a file.

    $h{foo} = "bar";
    $h{"answer to life, the universe, and everything"} = 42;
    
    open F, '>', 'have_seen.yaml';
    print F YAML::Syck::Dump( \%h );
    close F;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a subroutine as a member of a hash which
I would like to hash images, which have been converted to byte arrays. The
I have a ruby hash which looks like {10.1.1.6=>nick, 127.0.0.1=>nick1} But I can't manage
I have a string which looks like a hash: { :key_a => { :key_1a
i have a function that converts an array to a hash which i would
I have a hash of a random size, which may have values like 100
I have an array of fingerprints in hash buckets. I would like to insert
I have a twenty byte hex hash that I would like to store in
I have the following String[] temp; which returns red blue green I would like
I have a Ruby hash which looks like: { id => 123, name =>

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.